MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: NDSolve, Do loop, and Plot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg77308] Re: [mg77160] NDSolve, Do loop, and Plot
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Wed, 6 Jun 2007 07:26:23 -0400 (EDT)
  • References: <5670411.1181046423565.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

I suppose you're using version 6?

If so, Print solves the problem:

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}];
  Print@Plot[{Evaluate[x[t] /. mysol[w]],
     Evaluate[y[t] /. mysol[w]]}, {t, 0, 20}], {w, 2, 4}]

But I'd probably do it more like this:

Clear[mysol]
mysol[w_?NumericQ] :=
   Module[{x, y},
    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, All, -1]]];
Block[{$TextStyle = {FontFamily -> "Arial", FontSize -> 12,
     FontSlant -> "Italic"}},
  GraphicsColumn@
   Table[{x, y} = mysol[w]; Plot[{x[t], y[t]}, {t, 0, 20}], {w, 2, 4}]=

  ]

Bobby

On Tue, 05 Jun 2007 05:34:48 -0500, DBK <boydkramer at gmail.com> 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}]
>
>
>



-- =

DrMajorBob at bigfoot.com


  • Prev by Date: Re: $CellContext
  • Next by Date: Re: Iterate through a list help
  • Previous by thread: Re: NDSolve, Do loop, and Plot
  • Next by thread: Re: NDSolve, Do loop, and Plot