Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Topic: Varying a constant in an ODE to Manipulate solution
Replies: 10   Last Post: Jul 2, 2012 5:31 AM

 Messages: [ Previous | Next ]
 Bob Hanlon Posts: 695 Registered: 10/29/11
Re: Varying a constant in an ODE to Manipulate solution
Posted: Jun 14, 2012 5:34 AM

sol[c_] := {x[t], y[t], z[t]} /. First[
NDSolve[{y''[t] + Sin[y[t]/c] == 0,
y'[0] == 0, y[0] == 1/(1 + c),
x'[t] == t, x[0] == c^2,
z'[t] == 2 c x[t] - y[t], z[0] == 2},
{x, y, z}, {t, -3, 3}]]

Use a single Evaluate. For example,

Manipulate[
Plot[Evaluate[{sol[c][[1]], sol[c][[2]]}], {t, -3, 3},
PlotStyle -> {Green, Thick},
ImageSize -> 200,
AspectRatio -> Automatic,
PlotRange -> {{-3, 3}, {-1.05, 8.05}}],
{c, -0.5, 2, 0.2}]

Manipulate[
Plot[Evaluate[Most[sol[c]]], {t, -3, 3},
PlotStyle -> {Green, Thick},
ImageSize -> 200,
AspectRatio -> Automatic,
PlotRange -> {{-3, 3}, {-1.05, 8.05}}],
{c, -0.5, 2, 0.2}]

Manipulate[
Plot[Evaluate[Rest[sol[c]]], {t, -3, 3},
PlotStyle -> {Green, Thick},
ImageSize -> 200,
AspectRatio -> Automatic,
PlotRange -> {{-3, 3}, {-10, 10}}],
{c, -0.5, 2, 0.2}]

Manipulate[
Plot[Evaluate[Drop[sol[c], {2}]], {t, -3, 3},
PlotStyle -> {Green, Thick},
ImageSize -> 200,
AspectRatio -> Automatic,
PlotRange -> {{-3, 3}, {-10, 10}}],
{c, -0.5, 2, 0.2}]

Bob Hanlon

On Wed, Jun 13, 2012 at 4:57 AM, Narasimham <mathma18@hotmail.com> wrote:
> Same topic is continued. Thanks to Murray Eisenberg and Bob Hanlon
>
> All variables or a single variable are easily pocked out from sol[c_]
> list for plotting.
> But how to pick out two out of them for ParametricPlot ( 2D) ?
>
> sol[c_] := {x[t], y[t], z[t]} /.
> First[NDSolve[{y''[t] + Sin[y[t]/c] == 0, y'[0] == 0,
> y[0] == 1/(1 + c), x'[t] == t, x[0] == c^2,
> z'[t] == 2 c x[t] - y[t], z[0] == 2}, {x, y, z}, {t, -3, =

3}]]
> Manipulate[
> Plot[Evaluate[sol[c]], {t, -3, 3}, PlotStyle -> {Red, Thick},
> AspectRatio -> Automatic,
> PlotRange -> {{-3, 3}, {-10, 10}}], {c, -0.5, 2, 0.2}]
> Manipulate[
> Plot[Evaluate[sol[c][[1]]], {t, -3, 3}, PlotStyle -> {Red, Thick},
> AspectRatio -> Automatic,
> PlotRange -> {{-3, 3}, {-10, 10}}], {c, -0.5, 2, 0.2}]
> " 2 parameter Dynamic manipulation not OK "
> Manipulate[
> Plot[{Evaluate[sol[c][[1]]], Evaluate[sol[c][[1]]]}, {t, -3, 3},
> PlotStyle -> {Green, Thick}, AspectRatio -> Automatic,
> PlotRange -> {{-3, 3}, {-10, 10}}], {c, -0.5, 2, 0.2}]
>
> Regards
> Narasimham
>

Date Subject Author
6/14/12 Bob Hanlon
6/15/12 Murray Eisenberg
6/17/12 narasimham
6/19/12 narasimham
6/21/12 narasimham
6/22/12 narasimham
6/23/12 narasimham
7/1/12 narasimham
7/2/12 narasimham
7/2/12 narasimham