2
$\begingroup$

I have been using NDSolve and ParametricPlot3D without problems.

This is my code:

f[x_, y_] := (x^2 + y^2)/2
superficie := 
 ParametricPlot3D[{r*Cos[t], r*Sin[t], f[r*Cos[t], r*Sin[t]]}, {r, 0, 
   3}, {t, 0, 2*Pi}, PlotStyle -> Opacity[.5], Mesh -> None]

fx[x_, y_] = D[f[x, y], x];
fy[x_, y_] = D[f[x, y], y];

EcuacionDiferencial[{x0_, y0_}, {u0_, 
   v0_}] := {x''[t] == -fx[x[t], y[t]]/Sqrt[1 + (fx[x[t], y[t]])^2], 
  y''[t] == -fy[x[t], y[t]]/Sqrt[1 + (fy[x[t], y[t]])^2], x[0] == x0, 
  x'[0] == u0, y[0] == y0, y'[0] == v0}

TiempoFinal = 17;

PuntoInicial = {0, 1.3}; VelocidadInicial = {1, 0};

Soln := Flatten[
  NDSolve[EcuacionDiferencial[PuntoInicial, VelocidadInicial], {x, 
    y}, {t, 0, TiempoFinal}]]; 

r[t_] = {x[t], y[t], f[x[t], y[t]]} /. Soln;

Show[ParametricPlot3D[r[t], {t, 0, TiempoFinal}, 
  PlotStyle -> AbsoluteThickness[1]], superficie, PlotRange -> All]

It works plotting everything.

Now, I need to use a Manipulate command to make the 1.1 inside PuntoInicial, to fluctuate beetween 0.9 and 1.3.

Any ideas of how I could do that? I have been trying for 2 hours but nothing.

Thanks!!

$\endgroup$

1 Answer 1

2
$\begingroup$

I need to use a Manipulate command to make the 1.1 inside PuntoInicial, to fluctuate beetween 0.9 and 1.3

May be this can get you started.

ps. I changed all UpperCaseStartingNames to lowerCaseStartingNames since in Mathematica it is best not to start something with UpperCase letter.

enter image description here

Manipulate[
puntoInicial={0,to};
soln:=Flatten[NDSolve[ecuacionDiferencial[puntoInicial,velocidadInicial],
      {x,y},{t,0,tiempoFinal}]];

r[t_]={x[t],y[t],f[x[t],y[t]]}/.soln;

Show[
    ParametricPlot3D[r[t],{t,0,tiempoFinal},
    PlotStyle->AbsoluteThickness[1],PerformanceGoal->"Quality"],
    superficie,
    PlotRange->{{-3,3},{-3,3},{0,4}}, (*add to prevent shifting*)
    ImageSize->400,
    ImagePadding->20]
,

{{to,.9,"to"},.9,1.3,.01}, (*change as needed*)

TrackedSymbols:>{to},
SynchronousUpdating->True,SynchronousInitialization->True,
    FrameMargins->1,ImageMargins->1,
Initialization:> 
(
f[x_,y_]:=(x^2+y^2)/2;
superficie:=ParametricPlot3D[{r*Cos[t],r*Sin[t],f[r*Cos[t],r*Sin[t]]},
       {r,0,3},{t,0,2*Pi},PlotStyle->Opacity[.5],Mesh->None];

fx[x_,y_]=D[f[x,y],x];
fy[x_,y_]=D[f[x,y],y];

ecuacionDiferencial[{x0_,y0_},{u0_,v0_}]:={x''[t]==-fx[x[t],y[t]]/Sqrt[1+(fx[x[t],y[t]])^2],y''[t]==-fy[x[t],y[t]]/Sqrt[1+(fy[x[t],y[t]])^2],x[0]==x0,x'[0]==u0,y[0]==y0,y'[0]==v0};

tiempoFinal=17;
velocidadInicial={1,0};

)
]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.