Re: NDSolve, Do loop, and Plot

*To*: mathgroup at smc.vnet.net*Subject*: [mg77296] Re: NDSolve, Do loop, and Plot*From*: dh <dh at metrohm.ch>*Date*: Wed, 6 Jun 2007 07:20:08 -0400 (EDT)*References*: <f43ese$151$1@smc.vnet.net>

Hi, here is your clean up code, assuming you have not version 6: mysol[w_?NumericQ]:= NDSolve[{x'[t]\[Equal]-y[t]-x[t]^2,y'[t]\[Equal]w x[t]-y[t]^3, x[0]\[Equal]y[0]\[Equal]1},{x,y},{t,20}][[1]] Do[Plot[Evaluate[{x[t],y[t]}/.mysol[w]],{t,0,20}],{w,2,4}] hope this helps, Daniel 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}] > >