0
$\begingroup$
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[0] == a, y[0] == b}, {x, y}, {t, 0, endtime}, {a, b}]

Manipulate[
Show[fieldplot, ParametricPlot[{x[t] /. solns[[1]], y[t] /. solns[[1]]}, {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?

$\endgroup$
2

1 Answer 1

1
$\begingroup$
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[0] == a, y[0] == 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[0] == a, y[0] == 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"}]

fig1

$\endgroup$

Your Answer

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

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