NDSolve, Do loop, and Plot
- To: mathgroup at smc.vnet.net
- Subject: [mg77160] NDSolve, Do loop, and Plot
- From: DBK <boydkramer at gmail.com>
- Date: Tue, 5 Jun 2007 06:34:48 -0400 (EDT)
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}]