1
$\begingroup$

I want to plot the solution of a differential equation in a widget which lets me select an initial point of space and let it evolve according to the equation using an slider.

My code looks like this:

f[x_,y_]:=x-y+(x*y-x^3-x*y^2)/Sqrt[x^2 + y^2]
g[x_,y_]:=x+y-(x^2+x^2*y+y^3)/Sqrt[x^2 + y^2]

Manipulate[
   Module[{sol = 
    NDSolve[{x'[t]==f[x[t],y[t]],y'[t] == g[x[t],y[t]], x[0] == p[[1]], 
    y[0] == p[[2]]}, t,{y,0,T}, {x, 0, T}]},
    ParametricPlot[Evaluate[{x[t], y[t]} /. sol], {t, 0, T}, 
    PlotRange -> {{-4, 4}, {-3, 3}}]],
    {{p, {2, 1}}, Locator}, {{T, 10}, 0, 100}]

But while the slider is being shown, it does not behave correctly (the trajectory of each point is not being shown).

What is going on? How do I fix it?

$\endgroup$
2
$\begingroup$

I have corrected some syntax errors, check if this what is expected:

f[x_, y_] := x - y + (x*y - x^3 - x*y^2)/Sqrt[x^2 + y^2]
g[x_, y_] := x + y - (x^2 + x^2*y + y^3)/Sqrt[x^2 + y^2]

Manipulate[
sol = NDSolve[{x'[t] == f[x[t], y[t]], y'[t] == g[x[t], y[t]], 
x[0] == p[[1]], y[0] == p[[2]]}, {x, y}, {t, 0, T}]; 
ParametricPlot[Evaluate[{x[t], y[t]} /. sol], {t, 0, T}, 
PlotRange -> {{-4, 4}, {-3, 3}}],
{{p, {2, 1}}, Locator},
{{T, 10}, 0, 100}
]

enter image description here

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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