Simpsons Rule to Numerical integrate a function (Lorentzian Function)
이전 댓글 표시
Hi all, i'm trying to prove the Lorentzian Profile is Unit Normalized (i.e = 1) VIA Simpsons Rule of Integration. The constants are the given parameters
Here is my functon/code:
function s=simprl(f,a,b,M)
h=(b-a)/(2*M);
s1=0;
s2=0;
for k=1:M
x=a+h*(2*k-1);
s1=s1+f(x);
end
for k=1:(M-1)
x=a+h*2*k;
s2=s2+f(x);
end
s=h*(f(a)+f(b)+4*s1+2*s2)/3;
here is my function that i am calling with the given parameters entered in, it should equal to 1
simprl(@(x) (1./pi).*((5e8)./2)./(x-4.5667e14).^2 + ((4.5667e14)./2).^2,-Inf,Inf,2)
It should equal to 1, but instead it is giving me a "NaN" answer. What is wrong?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File 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!