# Re: Need help plotting multiple NDSolve solutions

• To: mathgroup@smc.vnet.net
• Subject: [mg10750] Re: Need help plotting multiple NDSolve solutions
• From: Allan Hayes <hay@haystack.demon.co.uk>
• Date: Mon, 2 Feb 1998 00:44:46 -0500
• References: <6a1q24\$q4n@smc.vnet.net> <6as96t\$f8j@smc.vnet.net>

```Norbert Scherm wrote:
>
> Van Graves wrote:
> >
> > Hi, I'm a new Mathematica user and would like to plot a "family" of
> > solutions for a set of simultaneous differential equations using
> > multiple sets of initial conditions.  I couldn't find an example in any
> > of the online documentation or on the Wolfram web site.  Can anyone
> > give me an example of how to do this?
>
> Fortunately, these days I dealt with a similar problem  (varying
> parameters of the ODE).
>
> -----------------------------------------------------------
>
> dfeld={(*
>        0.001,
>        0.1,
>        0.2,
>        0.3,*)
>        0.4,
>        0.5,
>        0.6,
>        0.7,
>        0.8,
>        0.9(*,
>        1.0,
>        1.5,
>        2.0,
>        3.0,
>        4.0,
>        5.0*)};
>
> Clear[y,x,d,Te];
>
> For[i=1,i<=Dimensions[dfeld][[1]],i++,
>   Print[Dimensions[dfeld][[1]]-i];
>   d=dfeld[[i]];
>   Te=2.0*Pi*1.75;
>   result=
>   NDSolve[
>     {x''[t]+2*d*x'[t]+x[t]==1.0,
>      x'[0]==0,
>      x[0]==0
>     },x,{t,0,Te}];
>     y[i]=(x/.result)[[1]];
>  g[i]=Plot[Evaluate[x[t]/.result],{t,0.0,Te},DisplayFunction->Identity];
> ];
> Show[
>   Table[ g[i],{i,Dimensions[dfeld][[1]]} ],
>   DisplayFunction->\$DisplayFunction
> ]
>
> -----------------------------------------------------------
>
> Instead of the parameter `d=dfeld[[i]]' you have to vary the  initials
> in each iteration of the loop.
>
> I hope this helps...
>
> (Norbert)

Another way?
Once the solutions are obtained the ParametricPlot (and Plot) can deal
with lists of functions.

In[1]:=
Apply[
NDSolve[{c'[t] == Cos[t],s'[t]== Sin[t],
s[0] ==#1, c[0] ==#2},{c[t],s[t]},{t,0,6}
]&,
{{0,.5},{.3,-.5}},
1
]

Out[1]=
{{{c[t] -> InterpolatingFunction[{{0., 6.}}, <>][t],

s[t] -> InterpolatingFunction[{{0., 6.}}, <>][t]}},

{{c[t] -> InterpolatingFunction[{{0., 6.}}, <>][t],

s[t] -> InterpolatingFunction[{{0., 6.}}, <>][t]}}}

In[2]:=

{c[t],s[t]}/.Flatten[%,1]

Out[98]=
{{InterpolatingFunction[{{0., 6.}}, <>][t],

InterpolatingFunction[{{0., 6.}}, <>][t]},

{InterpolatingFunction[{{0., 6.}}, <>][t],

InterpolatingFunction[{{0., 6.}}, <>][t]}}

In[3]:=
ParametricPlot[Evaluate[%],{t,0,6}]

--
Allan Hayes
Training and Consulting
Leicester, UK
hay@haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642

```

• Prev by Date: Dead keys in Mathematica for Linux
• Next by Date: RE: [Q] How to get rid of {} in lists?