Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

it is MATLAB code. Part 1 - use Simpson\'s rule to integrate y from a to b Creat

ID: 3714067 • Letter: I

Question

it is MATLAB code.

Part 1 - use Simpson's rule to integrate y from a to b Create a function with the headerline I simpson (x, y) where the inputs x and y are arrays. Your function should use Simpson's rule to find the area under the curve of y from a (the first point in x) to b (the last point in x) with a step size indicated by the x array. You may assume that x had a constant step size (h x (2)-x ( 1 ) ) Check your function (note: >> indicates something that I am typing in to the command window) >>x0:0.01:5; >Int simpson (x, y) 44.1667 >> --?"pi.pi/100:3"pi; x y cos (x) >> output simpson (x, y) output 1.9579e-15 Solution.zip CEACAA007URCSO.dat CEACAA007URBCI.dat 3 4 5 0

Explanation / Answer

function integral = simpson(y, x)
h = x(2) - x(1) ;
integral = (h/3) * (y(1) + y(end) + (4*sum(y(2:2:end))) + (2*sum(y(3:2:end))));
end


% The function name and the filename should be same and to be placed in
% the same folder where you are working. I have used the funtion name as
% simpson so I am naming my the file as simpson.m
% >> x = 0 : 0.01 : 5;
% >> y = x.^2 - x + 3;
% >> integral = simpson(y,x);
% >> integral
%
% integral =
%
% 44.3200
%
%
% >> x = (-3*pi) : (pi/100) : (3*pi);
% >> y = cos(x);
% >> integral = simpson(y,x);
% >> integral
%
% integral =
%
% -0.0209