Re: NDSolve, Do loop, and Plot

• To: mathgroup at smc.vnet.net
• Subject: [mg77238] Re: NDSolve, Do loop, and Plot
• From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
• Date: Wed, 6 Jun 2007 06:49:56 -0400 (EDT)
• Organization: Uni Leipzig
• References: <f43ese\$151\$1@smc.vnet.net>

```Hi,

when you see nothing, than you are working with
Mathematica 6.0 ??

Try

mysol[w_?NumericQ] :=
NDSolve[{x'[t] == -y[t] - x[t]^2, y'[t] == w x[t] - y[t]^3,
x[0] == y[0] == 1}, {x, y}, {t, 20}][[1]]

Manipulate[
DynamicModule[{sol},
sol = mysol[w];
Plot[{x[t], y[t]} /. sol, {t, 0, 20}, Evaluated -> True]], {w, 2.,
4}]

Regards
Jens

DBK wrote:
> This seems like it should be easy, but it is giving me problems. I am
> running some simulations and would like to simply substitute in a
> different parameter value (w below)  for each run of the simulation. I
> would then like to separately plot each variable (x and y below) for
> each simulation run with a different value for w. My code is below.
> When run, I get no error messages but no plot as well. I've tried
> pulling the Plot function out of the Do Loop but had no luck.
>
> Also, related to this, is it possible to provide mathematica with
> specific values of w instead of a range of values? For example, say I
> want to evaluate the simulation at w=2,5, and 14 instead of 2,3,4 as
> below.
>
> ClearAll["Global`*"];
> \$TextStyle = {FontFamily -> "Arial", FontSize -> 12,
>    FontSlant -> "Italic"};
> Do[mysol[w] =
>   NDSolve[{x'[t] == -y[t] - x[t]^2, y'[t] == w x[t] - y[t]^3,
>     x[0] == y[0] == 1}, {x, y}, {t, 20}];
>  Plot[{Evaluate[x[t] /. mysol[w]], Evaluate[y[t] /. mysol[w]]}, {t, 0,
>     20}], {w, 2, 4}]
>
>

```

• Prev by Date: Re: Segregating the elements of a list based on given lower and upper bounds
• Next by Date: Re: Hold and Simplify
• Previous by thread: Re: NDSolve, Do loop, and Plot
• Next by thread: Re: NDSolve, Do loop, and Plot