Home > K25104 > Integration > simpsons_alt_rule.m

simpsons_alt_rule

PURPOSE ^

Employs Simpson's 3/8 rule to integrate f between a and b

SYNOPSIS ^

function [ Q ] = simpsons_alt_rule( f,a,b )

DESCRIPTION ^

 Employs Simpson's 3/8 rule to integrate f between a and b
 Input arguments:
   f, function handle
   a,b, integration bounds, a<b
 Output arguments:
   Q, value of integral

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ Q ] = simpsons_alt_rule( f,a,b )
0002 % Employs Simpson's 3/8 rule to integrate f between a and b
0003 % Input arguments:
0004 %   f, function handle
0005 %   a,b, integration bounds, a<b
0006 % Output arguments:
0007 %   Q, value of integral
0008 
0009 % first check user inputs
0010 if isa(f,'function_handle')==0;
0011     error('input must be a function handle');
0012 elseif a>=b;
0013     error('invalid interval');
0014 end
0015 
0016 fa=feval(f,a);          % evaluate f(a)
0017 fc=feval(f,(2*a+b)/3);  % evaluate f((2a+b)/3))
0018 fd=feval(f,(a+2*b)/3);  % evaluate f((a+2b)/3))
0019 fb=feval(f,b);          % evaluate f(b)
0020 
0021 Q=(b-a)*(fa+3*fc+3*fd+fb)/8;   % evaluate Q according to Simpson's 3/8 rule
0022 end
0023

Generated on Mon 18-Jan-2016 10:25:49 by m2html © 2005