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.

回答(1 个)

Torsten
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 个评论
Amir Kleiner
Amir Kleiner 2019-1-26
I don't really understand your unswer...
By:
Fx(gamma((t(i+1)+t(i))/2)
Do you mean:
(Fx(gamma(t(i+1)))+Fx(gamma(t(i))))/2
Or do you mean something else?
Since both the path and the vector field are given only at specific time, I can't really use the value at an intermediate time.
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...
Torsten
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by