Answer to Question #185176 in MatLAB for sumu

Question #185176

Write a MATLAB program to solve the following integral using

Simpson’s 1/3rd Rule.


I=∫ p0 (ax3+bx2+cx+d) dx=?


Assign suitable values of a, b, c and d.

Also assume suitable values of p and step size h.

Compare your program result with original one.


1
Expert's answer
2021-04-26T02:15:36-0400
a = 1;  b = 2;  c = 3;  d = 4;
p = 1;
% integrate a*x^3 + b*x^2 + c*x + d from 0 to p using Simpson 1/3 rule
f = @(x) a*x.^3 + b*x.^2 + c*x + d;
n = 2; % interval numbers
h = p /n;
s = 0;
for i=1:2:n
    s = s + f(h*(i-1)) + 4 * f(h*i) + f(h*(i+1));
end
s = s * h /3;

% original integral is a/4*x^4 + b/3*x^3 + c/2*x^2 + d*x
i_real = a/4*p.^4 + b/3*p.^3 + c/2*p.^2 + d*p;
fprintf('Calculated Integral value: %f\n', s);
fprintf('Real Integral value is:    %f\n', i_real);

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS