Vector formulation of a system of ODEs for NDSolve

• To: mathgroup at smc.vnet.net
• Subject: [mg15551] Vector formulation of a system of ODEs for NDSolve
• From: phillips at crisx.com (Terry Phillips)
• Date: Tue, 26 Jan 1999 13:44:35 -0500 (EST)
• Organization: Los Alamos National Laboratory
• Sender: owner-wri-mathgroup at wolfram.com

I would like to solve a system of differential equations with NDSolve,
using a vector equation to formulate the equations.  For example,
taking an problem from Chris Barkers excellent tutorial on solving
differential equations with Mathematica
(http://mac205.sjdccd.cc.ca.us/ODE/ODE-h.html (thank you Chris!!)), the
system of differential equations:

(dx/dt)=-x+2y
(dy/dt)=2x-3y
x(0)=1
y(0)=2

is easily solved with NDSolve:

In[8]:=
Clear[x,y,t,sol1x,sol1y]

sol1=NDSolve[{x'[t]==-x[t]+2y[t],x[0]==1,y'[t]==2x[t]-3y[t],y[0]==2},{x[t],y[t]},{t,-1,2}]
Out[9]=
{{x[t]\[Rule]InterpolatingFunction[{{-1.,2.}},"<>"][t],y[t]\[Rule]InterpolatingFunction[{{-1.,2.}},"<>h"][t]}}

If I try to formulate this as a vector equation, where f[[1]]=x and
f[[2]]=y, and use the vector formulation in NDSolve,, I cannot find a
vector formulation of the problem that Mathematica will accept.  E.g.,

Clear[f,t]
Array[f,2]
sol1test=NDSolve[{f[[1]]'[t]==-f[[1]]+2f[[2]],f[[1]][0]==1,f[[2]]'[t]==2f[[1]]-3f[[2]],f[[2]][0]==2},{f[[1]][t],f[[2]][t]},{t,-1,2}]
{f[1],f[2]}

does not work, nor does:

Clear[f,t]
Array[f,2]
sol1test=NDSolve[{f'[t][[1]]==-f[t][[1]]+2f[t][[2]],f[0][[1]]==1,f'[t][[2]]==2f[t][[1]]-3f[t][[2]],f[0][[2]]==2},{f[t][[1]],f[t][[2]]},{t,-1,2}]

Is there any way to formulate a system of differential equations in a
vector format for solution by NDSolve?  I am using Mathematica 3.0 with
Windows NT4.0.  Thank you for any help you can give me. Terry Phillips
------  __o phillips at nospam.lanl.gov      -------  _`\<,_     Phone:
505 667-7379 US Mail: ESA-EPE, MS J576        ---- (*)/ (*)    FAX: 505
665-1323 Los Alamos National Laboratory                    Los Alamos,
NM 87545

• Prev by Date: Re: ListDensityPlot gives PostScript error
• Next by Date: Re: combining surface graphics
• Previous by thread: Comparison of Mathematica on Various Computers
• Next by thread: How to construct all possible orderings