Write a computer code to integrate a function using the Simp
Write a computer code to integrate a function using the Simpson\'s rule. The inputs should be the function f and the endpoints of the nodes a= x_0
Solution
%Created by myclassbook.wordpress.com (Mayuresh)
%Created on 24 May 2013
%Question: Evaluate the integral 1/(1+x) within limits 0 to 6
clc;
clear all;
close all;
f=@(x)x^2 * lnx; %Change here for different function
a=1;b=1.5; %Given limits
n=b-a; %Number of intervals
h=(b-a)/n;
p=0;
for i=a:b
p=p+1;
x(p)=i;
y(p)=1/(1+i); %Change here for different function
end
l=length(x);
x
y
answer=(h/3)*((y(1)+y(l))+2*(y(3)+y(5))+4*(y(2)+y(4)+y(6)))
