Re: NDSolve w/ vectors requires homogenous system in 5.0
- To: mathgroup at smc.vnet.net
- Subject: [mg43105] Re: NDSolve w/ vectors requires homogenous system in 5.0
- From: "Robert Knapp" <rknapp at wolfram.com>
- Date: Tue, 12 Aug 2003 04:43:15 -0400 (EDT)
- References: <bg7ur3$hfr$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
"Selwyn Hollis" <selwynh at earthlink.net> wrote in message news:bg7ur3$hfr$1 at smc.vnet.net... > I've just noticed the same problem with nonhomogeneous systems. > > For instance, this works: > > NDSolve[ > {x'[t] == {{-1, 1}, {1, -1}}.x[t], x[0] == {1, 1}}, > x, {t, 0, 1} ] > > but this doesn't: > > NDSolve[ > {x'[t] == {{-1, 1}, {1, -1}}.x[t] + {1, 0}, x[0] == {1, 1}}, > x, {t, 0, 1} ] > > Pretty lame. It may be lame, but it is a consequence of the way Mathematica evaluates expressions. Note that NDSolve has no special argument holding attributes, so its arguments are always evaluated before any attempt is made to solve the differential equations. That means in the second case, you are asking NDSolve to attempt to solve: NDSolve[{x'[t] == {1 + {{-1, 1}, {1, -1}} . x[t], {{-1, 1}, {1, -1}} . x[t]}, x[0] == {1, 1}}, x, {t, 0, 1}] In which the dimensions of x'[t] do not match the dimensions of x[t] because the {1,0} has been threaded over. If you want to prevent symbolic evaluations like this, you need to specify that through a function definition: f[x_?VectorQ] := {{-1, 1}, {1, -1}}.x + {1,0} ; NDSolve[{x'[t] == f[x[t]], x[0] == {1,1}}, x, {t,0,1}] In most cases where the vector-valued variables will be useful, it will be necessary to prevent symbolic evaluation of part of the equations. This sort of workaround solves the problem from the original message which started this thread. Rob Knapp Wolfram Research