# Work of a force field [closed]

I have a parameter curve in 3d:

r1[t_] := {Cos[2 Pi t], Sin[2 Pi t], t}
r2[t_] := {1, 0, t}
r3[t_] := {1 - 1/2 Sin[Pi t], 0, 1/2 - Cos[Pi t]}


with a vector field:

F[x_, y_, z_] := {-2 x y + z^3, -1 - x^2, 3 x z^2};

r = {x, y, z}


Now I want to calculate work of force field as the path integral for r1, r2 and r3 as a procedure, that uses arguments F(r) and r(t) and times t0 & t1.

Has someone an idea how to realize it into Mathematica code?

Thanks a lot!

looks great!

I also want to visualize the curves in a ParametricPlot3D, I did this:

r1[t] = ParametricPlot3D[{{Cos[2*Pi*t], Sin[2*Pi*t], t}}, {t, 0, 1}]
r2[t] = ParametricPlot3D[{{1, 0, t}}, {t, 0, 1}]
r3[t] = ParametricPlot3D[{{1 - 1/2*Sin[Pi*t], 0,
1/2*(1 - Cos[Pi*t])}}, {t, 0, 1}]


How can I define the path of the curves from (1,0,0) to (1,0,1) ?

## closed as off-topic by MarcoB, Henrik Schumacher, Αλέξανδρος Ζεγγ, zhk, bbgodfreyDec 24 '18 at 21:29

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Henrik Schumacher, Αλέξανδρος Ζεγγ, zhk, bbgodfrey
If this question can be reworded to fit the rules in the help center, please edit the question.

• It should be Cos[2*Pi*t] or Cos[2 Pi t], not cos(2*Pi*t). – Henrik Schumacher Dec 16 '18 at 12:56

It is more about physics, rather than Mathematica. You should express the work as follows: $$\int\vec{F}\cdot\vec{r}_1'(t)\, \mathrm dt$$ After that it is easy to write the Mathematica expression:

Integrate[
F[r1[t][], r1[t][], r1[t][]].D[r1[t], t], {t, t0, t1}]

(*  1/4 (-4 t0^3 Cos[2 \[Pi] t0] + 4 t1^3 Cos[2 \[Pi] t1] +
5 Sin[2 \[Pi] t0] + Sin[6 \[Pi] t0] - 5 Sin[2 \[Pi] t1] -
Sin[6 \[Pi] t1]) *)


The rest you can do analogously.

Have fun!

I guess codes below would work:

(F @@ #).D[#, t] & /@ {r1[t], r2[t], r3[t]} // Simplify
Integrate[%, {t, t0, t1}]


Here are two ways, one involving DSolve and differential one-forms (the first one is like the others, except for being packaged up in a line integral function). See this answer by LLlAMnYP for the DSolve approach.

ClearAll[lineInt];

(* integrate a vector field *)
lineInt[F_?VectorQ, c : (X_?VectorQ -> rt_?VectorQ), {t_, a_, b_},
opts : OptionsPattern[Integrate]] :=
Integrate[(F /. Thread[c]).D[rt, t], {t, a, b}, opts];

(* integrate a one form *)
oneFormQ[ω_, X_] := (* linear && homogenenous in differentials Dt@X *)
InternalLinearQ[ω, Dt[X]] && PossibleZeroQ[ω /. Thread[Dt[X] -> 0]];
lineInt[ω_, c : (X_?VectorQ -> rt_?VectorQ), {t_, a_, b_},
opts : OptionsPattern[DSolve]] := Module[{W},
DSolveValue[
{{Dt[W[t]] == ω, Dt[X] == Dt[rt]} /. Thread[X -> Through[X[t]]],
W[a] == 0, Through[X[a]] == rt /. t -> a},
W[b],
t, opts] /; oneFormQ[ω, X]
];

X = {x, y, z};

lineInt[(F @@ X).Dt[X], X -> r1[t], {t, t0, t1}] // RepeatedTiming
(*
{0.196, 1/4 (-4 t0^3 Cos[2 π t0] + 4 t1^3 Cos[2 π t1] +
5 Sin[2 π t0] + Sin[6 π t0] - 5 Sin[2 π t1] -
Sin[6 π t1])}
*)

lineInt[F @@ X, X -> r1[t], {t, t0, t1}] // RepeatedTiming
(*
{2.19, 1/4 (-4 t0^3 Cos[2 π t0] + 4 t1^3 Cos[2 π t1] +
5 Sin[2 π t0] + Sin[6 π t0] - 5 Sin[2 π t1] -
Sin[6 π t1])}
*)


Integrate must do a lot of checking that DSolve` skips, I guess.