Home > K25104 > Integration > booles_rule.m

booles_rule

PURPOSE ^

Employs Boole's rule to integrate f between a and b

SYNOPSIS ^

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

DESCRIPTION ^

 Employs Boole's rule to integrate f between a and b
 Input arguments:
   f, function handle
   a,b, integration bounds, a<b
 Outpur arguments:
   Q, value of integral

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ Q ] = booles_rule( f,a,b )
0002 % Employs Boole's rule to integrate f between a and b
0003 % Input arguments:
0004 %   f, function handle
0005 %   a,b, integration bounds, a<b
0006 % Outpur 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 f1=feval(f,(3*a+b)/4);  % evaluate f((3a+b)/4))
0018 fm=feval(f,(a+b)/2);    % evalaute f at midpoint
0019 f2=feval(f,(a+3*b)/4);  % evaluate f((a+3b)/4))
0020 fb=feval(f,b);          % evaluate f(b)
0021 
0022 % evaluate Q according to Boole's rule
0023 Q=(b-a)*(7*fa+32*f1+12*fm+32*f2+7*fb)/90; 
0024 
0025 end
0026

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