Simpsonn in Matlab


If we want to implement Simpsonn method in matlab, we can write down like codes below:

function N=simpsonn(f,a,b,p)
N=0;A=0;B=0;

%p=steps are used
%f=function;  a&b = lowe bound and upper bound
h=(b-a)/p;
for k=1:(p-1)/2
A=A+f((2*k*h)+a);
end
for k=1:(p/2),
B=B+f(((2*k-1)*h)+a);
end
N=(h/3)*(f(a)+f(b)+(2*A)+(4*B));
end

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s