Needs["VariationalMethods`"]
(*Find Lagrangian by computing the metric from the line element*)
Lagrange = Module[{}, z = f[x[t], y[t]]; r = {x[t], y[t], z};
ds = Sqrt[D[r, t] . D[r, t]];
ds*ds
];
Print["Lagrange=", Lagrange]
(*Mathematica differentiates everything and writes down the Euler \
Lagrange Equation for us*)
{eq1, eq2} = EulerEquations[Lagrange, {x[t], y[t]}, {t}];
(*Solve it,nb:since we only care about the distance we can put any \
time interval*)
S = NDSolve[{eq1, eq2, x[0] == x0, x[1] == x1, y[0] == y0,
y[1] == y1}, {x[t], y[t]}, {t, 0, 1}];
xsol[t_] := Evaluate[x[t] /. S[[1, 1]]]
ysol[t_] := Evaluate[y[t] /. S[[1, 2]]]
zsol[t_] := Evaluate[f[xsol[t], ysol[t]]];
solution =
ParametricPlot3D[{xsol[t], ysol[t], f[xsol[t], ysol[t]]}, {t, 0, 1},
PlotRange -> All, PlotStyle -> Red];
Show[surface, solution, ptsPlot]
distance =
NIntegrate[Sqrt[xsol'[t]^2 + ysol'[t]^2 + zsol'[t]^2], {t, 0, 1}] //
NumberForm[#, 10] &(*Arc Length*)
138 Aspen
- 2.1k
- 4
- 21