# How to use ParametricNDSolve with manipulate

Clear[Field, x, y];
Field[x_, y_] = {-0.036 x E^x^2 + 0.123 y, 0.123 x - 0.087 y E^y^2};
fieldplot = Table[Vector[Field[x, y]/(1 + Norm[Field[x, y]]), Tail -> {x, y}], {x, -1.25, 1.25, 2.5/10}, {y, -1.25, 1.25, 2.5/10}];

Clear[x, y, t, solns];

endtime = 100;

solns = ParametricNDSolve[{
x'[t] == -0.036 x[t] E^x[t]^2 + 0.123 y[t],
y'[t] == 0.123 x[t] - 0.087 y[t] E^y[t]^2,
x == a, y == b}, {x, y}, {t, 0, endtime}, {a, b}]

Manipulate[
Show[fieldplot, ParametricPlot[{x[t] /. solns[], y[t] /. solns[]}, {t, 0, endtime}, PlotStyle -> {{Red, Thickness[0.015]}}], Graphics[{Red, PointSize[0.06], Point[{a, b}]}], Axes -> True, AxesLabel -> {"x", "y"}, PlotRange -> All],

{{a, -1, "x-start"}, -1, 1, Appearance -> "Labeled"}, {{b, -1, "y-start"}, -1, 1, Appearance -> "Labeled"}]


I am trying to use Manipulate to change the values of a and b in my solns equation, and then use those values as initial conditions to the differential equation that I am solving. However, the curve does not appear when I try plotting my function.

How can I have the Manipulate function update the variables a and b in my solns equation, and then plot that differential equation?

• Does this example resolve your issues mathematica.stackexchange.com/questions/130346/…?
– Moo
Dec 11 '18 at 12:57
• You might like also this: Menu/Help/WolframDocumentation/LocatorPane/NeatExamples. Check the very last example here. Dec 11 '18 at 13:03

Clear[Field, x, y];
Field[x_, y_] = {-0.036 x E^x^2 + 0.123 y, 0.123 x - 0.087 y E^y^2};
fieldplot =
StreamDensityPlot[
Field[x, y]/(1 + Norm[Field[x, y]]), {x, -1.25, 1.25}, {y, -1.25,
1.25}];

Clear[X, Y, t];

endtime = 100;

X = ParametricNDSolveValue[{x'[t] == -0.036 x[t] E^x[t]^2 +
0.123 y[t], y'[t] == 0.123 x[t] - 0.087 y[t] E^y[t]^2,
x == a, y == b}, x[t], {t, 0, endtime}, {a, b}];
Y = ParametricNDSolveValue[{x'[t] == -0.036 x[t] E^x[t]^2 +
0.123 y[t], y'[t] == 0.123 x[t] - 0.087 y[t] E^y[t]^2,
x == a, y == b}, y[t], {t, 0, endtime}, {a, b}];

Manipulate[
Show[fieldplot,
ParametricPlot[{X[a, b], Y[a, b]}, {t, 0, endtime},
PlotStyle -> {{Red, Thickness[0.015]}}],
Graphics[{Green, PointSize[0.03], Point[{a, b}]}], Axes -> True,
AxesLabel -> {"x", "y"}, PlotRange -> All], {{a, -1, "x-start"}, -1,
1, Appearance -> "Labeled"}, {{b, -1, "y-start"}, -1, 1,
Appearance -> "Labeled"}] 