RE: assigning a set of initial values
- To: mathgroup at smc.vnet.net
- Subject: [mg43814] RE: [mg43805] assigning a set of initial values
- From: "David Park" <djmp at earthlink.net>
- Date: Tue, 7 Oct 2003 02:40:53 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Young, deqns[{a0_, b0_, c0_}, t0_] := {a'[t] == a[t]*(3 - a[t] - 2*b[t] - 3*c[t]), b'[t] == b[t]*(2 - a[t] - b[t]), c'[t] == c[t]*(4 - a[t] - b[t]), a[t0] == a0, b[t0] == b0, c[t0] == c0} But it is not easy to get a good plot of the three solutions on one graph. Here I use a LogLog plot to try to show all three functions and since a[t] soon bumps around zero I chopped it off. NDSolve has problems with some initial conditions. The following automatically solves and plots. Needs["Graphics`Graphics`"] Clear[a, b, c] dsols = First@NDSolve[deqns[{10000, 100, 100}, 0], {a, b, c}, {t, 0, 10}]; {a[t_], b[t_], c[t_]} = {a[t], b[t], c[t]} /. dsols; LogLogPlot[{If[a[t] <= 0, 10.*^-5, a[t]], b[t], c[t]}, {t, 0, 10}, PlotRange -> {{0.000001, 10}, {0.0001, 10000}}]; This could be written into one routine as follows. solveAndPlot[{a0_, b0_, c0_}, t0_] := Module[{deqns, dsols, a, b, c}, deqns = {Derivative[1][a][t] == a[t]*(3 - a[t] - 2*b[t] - 3*c[t]), Derivative[1][b][t] == b[t]*(2 - a[t] - b[t]), Derivative[1][c][t] == c[t]*(4 - a[t] - b[t]), a[t0] == a0, b[t0] == b0, c[t0] == c0}; dsols = First[NDSolve[deqns, {a, b, c}, {t, 0, 10}]]; {a[t_], b[t_], c[t_]} = {a[t], b[t], c[t]} /. dsols; LogLogPlot[{If[a[t] <= 0, 0.0001, a[t]], b[t], c[t]}, {t, 0, 10}, PlotRange -> {{0.000001,10},{0.0001,10000}}]] solveAndPlot[{10000, 100, 100}, 0] David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Young Kim [mailto:kim17 at fas.harvard.edu] To: mathgroup at smc.vnet.net Hi, Let's say there is a non-linear differential equations like the following sol = NDSolve[ {a'[t] == a[t] ( 3 - a[t] - 2 b[t] - 3 c[t] ), b'[t] == b[t] ( 2 - a[t] - b[t] ), c'[t] == c[t] (4 - a[t] - b[t])}, {a[t], b[t], c[t]}, {t,0,10}] Is there a way to systematiiclly specify the initial values to the above equation (e.g. in the table format) so that you can visualize the multiple trajectories on the same plane or in the same 3D space ? Thanks. Young