       Re: Matrix differential equation

• To: mathgroup at smc.vnet.net
• Subject: [mg51035] Re: Matrix differential equation
• From: p-valko at tamu.edu (Peter Valko)
• Date: Sat, 2 Oct 2004 03:18:15 -0400 (EDT)
• References: <ciua6v\$90v\$1@smc.vnet.net> <cj0n8p\$ldd\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```After exchanging several mails in the background I see what the
propblem is:

A = -{{1, 2, 3}, {4, 5 , 6}, {7, 8 , 9}};
K = -{{0, 10, 0}, {0, 0 , 0}, {0, 0 , 0}};
KT = Transpose[K];

and

matrixExpA = First[X /. NDSolve[X'[t] == 0.5*IdentityMatrix+ X +
K.X + X.KT && X == IdentityMatrix, X, {t, 0, 10}]]

does not work. The reason is, that Mathematica rearranges

0.5*IdentityMatrix+ X + K.X + X.KT

before it realizes that X is a 3 by 3 matrix.

To avoid the problem, first I write

A = -{{1, 2, 3}, {4, 5 , 6}, {7, 8 , 9}};
K = -{{0, 10, 0}, {0, 0 , 0}, {0, 0 , 0}};
KT = Transpose[K];

then I write:
f[X_]:= 0.5*IdentityMatrix+ X + K.X + X.KT /; Dimensions[X]=={3,3}

This way I have a right-hand-side that will evaluate only if Mathematica
already knows that X is a 3 by 3 matrix.

Now
matrixExpA = First[X /. NDSolve[X'[t] == f[X[t]] && X ==
IdentityMatrix, X, {t, 0, 10}]]

works and provides an interpolating function. Finally,

matrixExpA[1.]   evaluates to
{{311.319, -32.1828, 0.}, {-32.1828, 3.57742, 0.}, {0., 0., 3.57742}}

Regards
Peter

p-valko at tamu.edu (Peter Valko) wrote in message news:<cj0n8p\$ldd\$1 at smc.vnet.net>...
> I tried to reproduce the error message, but surprisingly, there was no
> error and the sample problem worked.
>
> The result is an
>  InterpolatingFunction[{{0., 10.}}, <>]
> and I can calculate it at time zero or at time = 1.
>
> For instance
>  matrixExpA
> gives
> {{166.52, -16.4872, 0.}, {-16.4872, 1.64872, 0.}, {0., 0., 1.64872}}
>
>
> Therefore, I have to conclude, that you do not input exactly what you
> wish to input, or that something is not Cleared before you use it.
>
> I would suggest to print out
> k
> A
> K
> KT
> before using the command
>
> > matrixExpA =
> >   X /. First[
> >       NDSolve[X'[t] == 0.5*IdentityMatrix +(X[t]) + K.X[t] + X[t].KT &&
> >           X == IdentityMatrix, X, {t, 0, 10}]]
>
>
> to make sure that they really have the value I think they have.
>
> Regards
> Peter
>
>
>
> "Marco Malvaldi" <M.Malvaldi at chem.rug.nl> wrote in message news:<ciua6v\$90v\$1 at smc.vnet.net>...
> > It is possible to numerically solve a general matrix differential equation
> > with Mathematica? From the example in Mathematica 5 tutorial, I found that
> > this problem can be solved:
> >
> > k = 10
> > A = -{{1, 2, 3}, {4, 5 , 6}, {7, 8 , 9}};
> > K = -{{0, k, 0}, {0, 0 , 0}, {0, 0 , 0}};
> > X0 = {{1, 0, 0}, {0, 1 , 0}, {0, 0 , 1}};
> > KT = Transpose[K]
> >
> > matrixExpA =
> >   X /. First[
> >       NDSolve[X'[t] == 0.5*IdentityMatrix .(X[t]) + K.X[t] + X[t].KT &&
> >           X == IdentityMatrix, X, {t, 0, 10}]]
> >
> > Anyway, when I try to submit this problem:
> >
> > matrixExpA =
> >   X /. First[
> >       NDSolve[X'[t] == 0.5*IdentityMatrix +(X[t]) + K.X[t] + X[t].KT &&
> >           X == IdentityMatrix, X, {t, 0, 10}]]
> >
> >
> > NDSolve::ndfdmc: Computed derivatives do not have dimensionality consistent
> > with the initial conditions.
> >
> > even if what I'm doing is to sum a 3x3 matrix to a system of 3X3 matrix.
> >
> > Regards
> > Marco Malvaldi

```

• Prev by Date: Re: Hyperbolic function identity
• Next by Date: Re: Re: Linear Programming
• Previous by thread: A better Implicit Mandelbrot
• Next by thread: suggestion for frontend