       Re: NDSolve and vector functions

• To: mathgroup at smc.vnet.net
• Subject: [mg87881] Re: NDSolve and vector functions
• From: Szabolcs Horvát <szhorvat at gmail.com>
• Date: Sat, 19 Apr 2008 03:35:02 -0400 (EDT)
• Organization: University of Bergen
• References: <fu9vl0\$ie2\$1@smc.vnet.net>

```dh wrote:
> Hello all,
>
> does anybody know a way to compute a vector valued function using
>
> NDSolve without explicitely specifying all vector components. Here is a
>
> simple example: Although NDSolve[{p'[t]==p[t],p=={1,0}},p,{t,0,1}] works,
>
> NDSolve[{p'[t]==p[t]+{1,1},p=={1,0}},p,{t,0,1}]
>
> does not work because p[t] in "p[t]+{1,1}"  is treated as a scalar and
>
> the expression is evaluated to {1+p[t],1+p[t]} what is clearly not
>
> intended. Even in "IdentityMatrix.p[t]+{1,1}"
>
> "IdentityMatrix.p[t]" is treated like a scalar and added to the
>
> components of {1,1}.
>
> do I miss something???

Hi Daniel,

Obviously, there are workarounds, but they might not be pretty ... I
think that this is a fundamental limitation of Mathematica ... Most
functions (incuding Plus) assume that symbols represent scalars ...

A workaround is to define a new `plus' function that is only evaluated
when its arguments are vectors:

vecPlus[arg__?VectorQ] := Plus[arg]

Now this works:

f = p /. First@
NDSolve[{p'[t] == vecPlus[p[t], {1, 1}], p == {1, 0}},
p, {t, 0, 1}]

Plot[f[x], {x, 0, 1}]

One disadvantage of this approach is that it prevents NDSolve from
transforming the ODE symbolically.  But this is really a limitation
stemming from using vector functions, and not a problem introduced by
vecPlus.  A more serious problem is that most probably vecPlus cannot be
compiled, so this might slow NDSolve down.

Szabolcs

```

• Prev by Date: Re: NDSolve and vector functions
• Next by Date: Re: Re: Abs[x] function
• Previous by thread: Re: NDSolve and vector functions
• Next by thread: Re: NDSolve and vector functions