Interacting with the solution of an autonomous differential equation

1

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?

Jsevillamol

Posted 2017-11-23T20:17:27.700

Reputation: 113

Answers

2

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

José Antonio Díaz Navas

Posted 2017-11-23T20:17:27.700

Reputation: 5 835