Professional Documents
Culture Documents
Boole
Boole
1. M-FILE BOOLE
% Usage: r = boole(f,a,b,n)
% Composite Boole's (aka Bode's) rule (5-point closed Newton-Cotes)
%
% Input:
% f - Matlab inline function
% a,b - integration interval
% n - number of subintervals (panels)
%
% Output:
% r - computed value of the integral
%
% Examples:
% r=boole(@sin,0,1,10);
% r=boole(@myfunc,0,1,10);
% r=boole(inline('sin(x)'),0,1,10);
% r=boole(inline('sin(x)-cos(x)'),0,1,10);
function r = boole(f,a,b,n)
h = (b - a) / (n * 4);
r = 7 * f(a);
x = a + h;
for i = 1 : n-1
r = r + 32 * f(x);
x = x + h;
r = r + 12 * f(x);
x = x + h;
r = r + 32 * f(x);
x = x + h;
r = r + 14 * f(x);
x = x + h;
end;
r = r + 32 * f(x);
x = x + h;
r = r + 12 * f(x);
x = x + h;
r = r + 32 * f(x);
r = r + 7 * f(b);
r = r * h*2/45;
1.a. Command Window
>> f=inline('sqrt(1+x^3)')
f=
Inline function:
f(x) = sqrt(1+x^3)
>> a=-1
a=
-1
>> b=1
b=
>> n=8
n=
>> r = boole(f,a,b,n)
r=
1.9508
f=
Inline function:
f(x) = x*tan(x)
>> a=0
a=
>> b=pi/4
b=
0.7854
>> n=6
n=
>> r = boole(f,a,b,n)
r=
0.1858
2. Command Window
>> f=inline('1/sqrt(1-(0.1284.*(sin(x)).^2))')
f=
Inline function:
f(x) = 1/sqrt(1-(0.1284.*(sin(x)).^2))
>> a=0
a=
>> b=pi/2
b=
1.5708
>> n=4
n=
>> r = boole(f,a,b,n)
r=
1.6252