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.

采纳的回答

darova
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 CenterFile Exchange 中查找有关 Bessel functions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by