Code covered by the BSD License  

Highlights from
Simpson method

Simpson method

by

 

Simpson method

Simpson.m
function S=Simpson(f,t,n)
%f:x:䡣n:nȷ֡
syms x
h=(t(2)-t(1))/n;
ti=linspace(t(1),t(2),n+1);
s1=0;
for i=2:n
    s1=s1+subs(f,x,ti(i));
end
s2=0;
for i=1:n
    x0=(ti(i)+ti(i+1))/2;
    s2=s2+subs(f,x,x0);
end
S=h*(subs(f,x,ti(1))+4*s2+2*s1+subs(f,x,ti(n+1)))/6;

Contact us