Numerical integration using Simpsons

1 次查看(过去 30 天)
Simpsons numerical integration to evalaute
lambda=0.0:0.1:1
mu2=0.5;
gamma2=0.7;
zeta=0.1;
a=0;%lower limit
b=1;%upper limit
n=10;%number of sub-intervals
h=(b-a)/n;
f3=@(x,p)(x.^((mu2/zeta)-1)).*((1-x).^((gamma2./zeta))).*(exp(-(lambda(p).*x)./zeta));
for p = 1:numel(lambda)
for k=1:n
x(k)=a+k*h;
y(k)=f3(x(k),p);
end
so=0;se=0;
for k=1:n-1
if rem(k,2)==1
so=so+y(k);%sum of odd terms
else
se=se+y(k); %sum of even terms
end
end
I3(p)=h./3.*(f3(a,p)+f3(b,p)+4.*so+2.*se)
end
For 11 values of lambda, i am getting 61 solutions. Please help me to find the error.

采纳的回答

Alan Stevens
Alan Stevens 2020-11-10
I just get 11 values for I3, running your code!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by