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

Simpson rule: please see the equation by serching in the google as i was unable

ID: 2988641 • Letter: S

Question

Simpson rule: please see the equation by serching in the google as i was unable to paste it here.

Make a function using this as the function's first few lines:

function result = simpson(f, a, b)

% f is a vector having the values f(x0) to f(xn)

% simpson(x) returns the numerical value of Sn

% note that x0 = a and xn = b and f has n+1 values (for x 0 through n)

% n is determined by the length of vector f Compute the integral x^2dx .limit from 0 to 1. using this function with a vector f having 25 values from 0 to 1. Note that the actual value is 1/3.

Explanation / Answer

function result = simpson(f,a,b)

result2=0;
result3=0;
h=(b-a)/length(f);
result1 = (h*(f(1) + f(length(f))))/3;
for i =2:(length(f)-1)
if(mod(i,2)==0)
result2=result2+(f(i)*(4*h/3));
else
result3=result3+(f(i)*(2*h/3));
end
end
result = result1+result2+result3;