Question: % SIMPSON'S COMPOSITE ALGORITHM 4 . 1 % % To approximate I = integral ( ( f ( x ) dx ) ) from a

% SIMPSON'S COMPOSITE ALGORITHM 4.1
%
% To approximate I = integral (( f(x) dx )) from a to b:
%
% INPUT: endpoints a, b; even positive integer n.
%
% OUTPUT: approximation XI to I.
syms(OK,A,B,N,H,XI0,XI1,XI2,NN,I,X,XI,s,x);
TRUE =1;
FALSE =0;
fprintf(1,'This is Simpsons Method.
');
fprintf(1,'Input the function F(x) in terms of x
');
fprintf(1,'For example: cos(x)
');
s = input('','s');
F = inline(s,x);
OK = FALSE;
while OK == FALSE
fprintf(1,'Input lower limit of integration and ');
fprintf(1,'upper limit of integration
');
fprintf(1,'on separate lines
');
A = input('');
B = input('');
if A > B
fprintf(1,'Lower limit must be less than upper limit
');
else
OK = TRUE;
end
end
OK = FALSE;
while OK == FALSE
fprintf(1,'Input an even positive integer N.
');
N = input('');
if N >0 && rem(N,2)==0
OK = TRUE;
else
fprintf(1,'Input must be even and positive
');
end
end
if OK == TRUE
% STEP 1
H =(B-A)/N;
% STEP 2
XI0= F(A)+ F(B);
% summation of f(x(2*I-1))
XI1=0.0;
% summation of f(x(2*I))
XI2=0.0;
% STEP 3
NN = N -1;
for I =1:NN
% STEP 4
X = A + I * H;
% STEP 5
if rem(I,2)==0
XI2= XI2+ F(X);
else
XI1= XI1+ F(X);
end
end
% STEP 6
XI =(XI0+2.0* XI2+4.0* XI1)* H /3.0;
% STEP 7
fprintf(1,'
The integral of F from %12.8f to %12.8f is
', A, B);
fprintf(1,'%12.8f
', XI);
end
Please input the correct info to compute the following:
Integral 1-->2 of x ln(x) dx , n =4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!