Numerical calculation of line integral over a vector field
12 ビュー (過去 30 日間)
古いコメントを表示
Hey,
I have a path given by three vectors and a vector field also given by three vectors, evaluated only along the path - .
I need to find the line integral .
My problem is that the length of is different from the length of and if I truncate it in different form I get very different results:
% The vector field is Fx, Fy, Fz
% The path is rx, ry, rz
% the time vector is t
% all 7 vectors have the same size.
dt = diff(t);
drx=diff(rx)./dt; dry=diff(ry)./dt; drz=diff(rz)./dt;
%% 1st try:
Fx=Fx(1:end-1); Fy=Fy(1:end-1); Fz=Fz(1:end-1);
t = t(1:end-1);
%%2nd try:
Fx=Fx(2:end); Fy=Fy(2:end); Fz=Fz(2:end);
t=t(2:end);
%% integral calculation
Fdr = Fx.*drx + Fy.*dry + Fz.*drz;
W = cumtrapz(t,Fdr)
plot(t,W)
The 1st try code results in an increasing function, while the 2nd try code results in a decreasing function.
I'd appreciate some help with this integration.
0 件のコメント
回答 (1 件)
Torsten
2019 年 1 月 25 日
The usual way is to approximate the integral as
sum_{i=1}^{n-1} [ (rx(t(i+1))-rx(t(i))/(t(i+1)-t(i)) * Fx(gamma((t(i+1)+t(i))/2) + ...
(ry(t(i+1))-ry(t(i))/(t(i+1)-t(i)) * Fy(gamma((t(i+1)+t(i))/2) + ...
(rz(t(i+1))-rz(t(i))/(t(i+1)-t(i)) * Fz(gamma((t(i+1)+t(i))/2) ]
2 件のコメント
Torsten
2019 年 1 月 28 日
編集済み: Torsten
2019 年 1 月 28 日
>By:
>Fx(gamma((t(i+1)+t(i))/2)
>Do you mean:
>(Fx(gamma(t(i+1)))+Fx(gamma(t(i))))/2
Yes, that's what I mean.
> Also, this seems like a Riemann approximation for the integral, which is fine, but doesn't really unswer the question of how to calculate this integral in MatLab...
Sums can also programmed in MATLAB ...
But this is shorter:
dt = diff(t);
drx=diff(rx)./dt;
dry=diff(ry)./dt;
drz=diff(rz)./dt;
t = (t(1:end-1)+t(2:end))/2.0;
Fx = (Fx(1:end-1)+Fx(2:end))/2.0;
Fy = (Fy(1:end-1)+Fy(2:end))/2.0;
Fz = (Fz(1:end-1)+Fz(2:end))/2.0;
%% integral calculation
Fdr = Fx.*drx + Fy.*dry + Fz.*drz;
W = cumtrapz(t,Fdr)
plot(t,W)
Best wishes
Torsten.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!