Integration Limits on Trapz
12 ビュー (過去 30 日間)
古いコメントを表示
Hi Everyone!
I have a very simple question. I used MATLAB to solve a set of coupled ODEs from zero to Inf. And now I have the vectors containing the solution for these functions and their first derivatives in this semi-infinite interval.
My question is: How can I ask trapz to integrate a functional (depending on these solutions and their derivatives) from xmin=1e-5 to xmax=100, only? Is it enough to insert extra inputs into trapz?
Thank you,
MdL.
0 件のコメント
採用された回答
Walter Roberson
2021 年 2 月 24 日
x = sort(rand(1,20));
y = exp(sin(2*pi*x));
yint = cumtrapz(x, y);
plot(x, y, 'k', x, yint, 'b')
syms X B
Y = exp(sin(2*pi*X));
Yint = int(Y, X, 0, X);
fplot([Y, Yint], [0 1])
This illustrates that you can use trapz() with irregular spacing, and that if the values are close enough, it will approximate the true integral.
If you only want to integrate over a particular range, then find the endpoints of the range in the data and only do that portion:
mask = pi/10 <= x & x <= 2*pi/10;
px = x(mask);
py = y(mask);
pyint = cumtrapz(px, py);
plot(px, py, 'k', px, pyint, 'b')
The reason this does not look the same is that you are not bringing in the accumulated value from 0 to pi/10, and definite integration always starts at 0.
9 件のコメント
Walter Roberson
2021 年 2 月 24 日
Watch out for the places you had 1/s.sx1tau : s.sx1tau is a vector so 1/ it is matrix division . Notice I corrected them to 1./
The .* I put in are important too.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


