I am having issues using Manipulate
to plot the (numeric) solution to an ODE for different parameter values.
I have a code that has several stages, which seem to all work when I do them one after another. This code solves a system of ODEs (for particular parameter values), then does a parametric plot of the solution. The problem is I need to put the lines together to wrap them around with Manipulate
(for I can do this code again easily for different parameter values), and this is causing me a lot of pain.
My initial code is:
(*this is my ODE*)
unforced[x0_, p0_, α_:α, δ_:δ] :=
{x'[t] == p[t],
p'[t] == -α x[t] - δ p[t] + α (x[t])^3,
x[0] == x0,
p[0] == p0
}
(*Choose some parameter values*)
α = -1, δ = 1
(*Solve my ODE*)
s = NDSolve[unforced[x0 = 1, p0 = 1], {x, p}, {t, 20}]
(*Plot It*)
ParametricPlot[Evaluate[{x[t], p[t]} /. s], {t, 0, 20}]
But now I want to be able to Manipulate
the parameter values α
and δ
. So I start putting the lines of code together... and problems happen.
ParametricPlot[Evaluate[{x[t], p[t]}/.
NDSolve[{x'[t] == p[t],
p'[t] == -α x[t] - δ p[t] + α (x[t])^3,
x[0] == 1, p[0] == 0}, {x, p}, {t, 20}]], {t, 0, 20}]
This plots an empty graph. This confuses me because it seems like all I did was substitute into my previous code. Because this doesn't work, I can't put a Manipulate
around this. If it worked then I would have tried:
Manipulate[ParametricPlot[Evaluate[{x[t], p[t]} /.
NDSolve[{x'[t] == p[t],
p'[t] == -α x[t] - δ p[t] + α (x[t])^3,
x[0] == 1, p[0] == 0}, {x, p}, {t, 20}]], {t, 0, 20}],
{{α, -1, "α"}, -2, 0}, {{δ, 0, "δ"}, 0, 2}]
How do I get around this problem?
Comments
Post a Comment