Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #3945 > unrolled thread

NDSolve in matrix form

Started byGlenn Carlson <g.crlsn@gmail.com>
First post2011-07-24 07:22 +0000
Last post2011-07-24 11:40 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  NDSolve in matrix form Glenn Carlson <g.crlsn@gmail.com> - 2011-07-24 07:22 +0000
    Re: NDSolve in matrix form "Kevin J. McCann" <kjm@KevinMcCann.com> - 2011-07-24 11:40 +0000

#3945 — NDSolve in matrix form

FromGlenn Carlson <g.crlsn@gmail.com>
Date2011-07-24 07:22 +0000
SubjectNDSolve in matrix form
Message-ID<j0gh6t$bd4$1@smc.vnet.net>
I am trying to numerically solve systems of ODEs using Mathematica 7.

The desired accuracy that I am striving for depends on the number of solution functions so I want to structure my solution algorithm to allow different numbers of solution functions. Solving the problem as a system of ODEs in matrix form seems the logical choice:

     dX/dt = f[X[t]],

where f[X[t]] is a specified function, and X[t] is a vector of solution functions {x1[t],x2[t],...}. The initial conditions are specified by a vector X[0] = {x1[0],x2[0],...}.

In my problem, the number of solution functions will usually vary from 3 to 7, but could be any number.

One approach that doesn't work is:

     f := {f[[1]][t], f[[2]][t], f[[3]][t]}
     fInit := {0, 0, 2}
     mat := {(-3*f[[1]][t] - f[[2]][t]), 26.5*f[[1]][t] - f[[2]][t] - f[[1]][t]*f[[3]][t], f[[1]][t]*f[[2]][t] - f[[3]][t]}
     solution =  NDSolve[{Derivative[1][f][t] == mat, f[0] == fInit}, f, {t, 0, 17}]

I don't know if the problem is in the way f is specified or in my expression for NDSolve.

I'd appreciate any assistance.

Thanks and regards,

Glenn

[toc] | [next] | [standalone]


#3948

From"Kevin J. McCann" <kjm@KevinMcCann.com>
Date2011-07-24 11:40 +0000
Message-ID<j0h0c0$dhb$1@smc.vnet.net>
In reply to#3945
Glenn,

First of all, you got into a recurrence problem with you definition of 
f. Second, the form of the input to NDSolve isn't quite right, you need 
to use Thread to transform something like

{f1[t],f2[t],f3[t]}=={0,0,2} into {f1[t]==0,f2[t]==0,f3[t]==2}

Take the code below apart and you will see how this is used.

Finally, note that f3 does not enter the first two de's and that it is 
fairly simple to see that f1=f2=0.

Here is my take:

Clear[f,fInit,mat]
f[t_]={f1[t],f2[t],f3[t]}
fInit={0,0,2}
mat={-3 f1[t]-f2[t],26.5 f1[t]-f2[t]-f1[t] f2[t],f1[t] f2[t]-f3[t]}
eqns=Flatten[{Thread[(f^\[Prime])[t]==mat],Thread[f[0]==fInit]}]
solution=NDSolve[eqns,f[t],{t,0,17}][[1]]

Cheers,

Kevin

On 7/24/2011 3:22 AM, Glenn Carlson wrote:
> I am trying to numerically solve systems of ODEs using Mathematica 7.
>
> The desired accuracy that I am striving for depends on the number of solution functions so I want to structure my solution algorithm to allow different numbers of solution functions. Solving the problem as a system of ODEs in matrix form seems the logical choice:
>
>       dX/dt = f[X[t]],
>
> where f[X[t]] is a specified function, and X[t] is a vector of solution functions {x1[t],x2[t],...}. The initial conditions are specified by a vector X[0] = {x1[0],x2[0],...}.
>
> In my problem, the number of solution functions will usually vary from 3 to 7, but could be any number.
>
> One approach that doesn't work is:
>
>       f := {f[[1]][t], f[[2]][t], f[[3]][t]}
>       fInit := {0, 0, 2}
>       mat := {(-3*f[[1]][t] - f[[2]][t]), 26.5*f[[1]][t] - f[[2]][t] - f[[1]][t]*f[[3]][t], f[[1]][t]*f[[2]][t] - f[[3]][t]}
>       solution =  NDSolve[{Derivative[1][f][t] == mat, f[0] == fInit}, f, {t, 0, 17}]
>
> I don't know if the problem is in the way f is specified or in my expression for NDSolve.
>
> I'd appreciate any assistance.
>
> Thanks and regards,
>
> Glenn
>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web