Hi All,
I am currently trying to do some integration using the Simpson's rule. My codes does produce the required approximation. But I don't understand how I can obtain a plot of the number of panels (x-axis) vs the integral evaluated at each panel (y-axis). My code uses 10 panels. The plot should be some what of a zig zag in appearance. Could someone please provide some assistance regarding this matter?
My code is shown below:
%Function to be integrated
f=@(x)exp(x); %lower limit
a=0;%upper limit
b=1; %number of panels
n=10; %interval size
h=(b-a)/n;%summation of first two values
s=f(a)+f(b);%loop for the rest of the calculations
for i=1:2:n-1 s=s+4*f(a+i*h); %summation
endfor i=2:2:n-2 s=s+2*f(a+i*h); %summationend%evaluate integral
I=h/3*s
Best Answer