Why cumtrapz does not give same results as my analytic solution?
3 次查看(过去 30 天)
显示 更早的评论
I wanted to test a numerical integration routine and used the following test function:
x=linspace(-10,10,100);
xs=x/30;
y=besselj(0,xs.*x).*x;
Yan=besselj(1,xs.*x(end)).*x(end)./xs;
Ynum=cumtrapz(x,y);
hold on
plot(xs,abs(Yan).^2,'b')
plot(xs,abs(Ynum).^2,'--r')
legend('Analytic result','Numeric result');
grid on
hold off

Unfortunately my results are not the same. I hope someone could give an explanation why they are not the same, my guess there is some scaling that goes wrong.
0 个评论
采纳的回答
darova
2021-3-15
I think it happens because of limits of integration
x = linspace(-2,3);
y = x.^2;
c0 = x(1)^3/3;
plot(x,cumtrapz(x,y),'.-r')
line(x,x.^3/3-c0) % try without c0
3 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Bessel functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!