:

Block matrix computations with linalg or LinearAlgebra?

I am trying to manipulate some equations of motion in block matrix form. My first attempt is with the old linalg package because I don't want the submatrices to expand until I am ready However, linalg is not working as I expected. In particular, the formation of EoM1 in the eample below does not lead the &* operator propagating into a block matrix multiplication. If there is a better way to do this with the Linear Algebra package, I would sure like to see an example. Failing that, what am I doing wrong in the linalg example? The example is a linear case. I also will be trying to do nonlinear cases involving multiple block matrix multiplications. The example below is in the old text ouput (edited for clarity). I have been unable to get worksheets to upload successfully into MaplePrimes. Any help will be greatly appreciated.

Thanks,

Neill Smith

# Equations of motion in matrix form in linalg package.

> restart;

> with(linalg);

# Define*simple*matrices and vectors;

> TAM := matrix(3, 3, [Xud, 0, 0, 0, Yvd, 0, 0, 0, Zwd]);

[Xud   0    0 ]

TAM := [ 0   Yvd   0 ]

[ 0    0   Zwd]

> TRAM := matrix(3, 3, [0, Xqd, 0, Ypd, 0, Yrd, 0, Zqd, 0]);

[ 0   Xqd   0 ]

TRAM := [Ypd   0   Yrd]

[ 0   Zqd   0 ]

> RAM := matrix(3, 3, [Kpd, 0, Krd, 0, Mqd, 0, Npd, 0, Nrd]);

[Kpd   0   Krd]

RAM := [ 0   Mqd   0 ]

[Npd   0   Nrd]

> RTAM := matrix(3, 3, [0, Kvd, 0, Mud, 0, Mwd, 0, Nvd, 0]);

[ 0   Kvd   0 ]

RTAM := [Mud   0   Mwd]

[ 0   Nvd   0 ]

> Vel := matrix(3, 1, [u, v, w]);

[u]

Vel := [v]

[w]

> Omg := matrix(3, 1, [p, q, r]);

[p]

Omg := [q]

[r]

# Create matrix EoM by 1st method

> MAM := matrix(2, 2, ['TAM', 'TRAM', 'RTAM', 'RAM']);

[TAM   TRAM]

[RTAM  RAM ]

> MAM;

MAM

> evalm(MAM);

[TAM   TRAM]

[RTAM  RAM ]

> S := matrix(2, 1, ['Vel', 'Omg']);

[Vel]

S := [   ]

[Omg]

> S;

S

> evalm(S);

[Vel]

[Omg]

> EoM := `&*`(MAM, S);

EoM := MAM &* S

> EoM;

MAM &* S

> EoM1 := evalm(EoM);

[TAM Vel + TRAM Omg]

[RTAM Vel + RAM Omg]

# However, note that the &* operator did not "propagate" inside of the definition of matrix EoM1.

> EoM1;

EoM1

> evalm(EoM1);

[TAM Vel + TRAM Omg]

[RTAM Vel + RAM Omg]

> evalm(EoM1[1]);

Error, array defined with 2 indices, used with 1 indices

> evalm(EoM1[1, 1]);

Error, (in evalm/evaluate) use the &* operator for matrix/vector multiplication

# As noted above the &* operator did not "propagate" inside of the definition of matrix EoM1.

# What we would really like to get would be

> EoM2 := matrix(2, 1, [`&*`('TAM', 'Vel')+`&*`('TRAM', 'Omg'), `&*`('RTAM', 'Vel')+`&*`('RAM', 'Omg')]);

[TAM &* Vel + TRAM &* Omg]

EoM2 := [                        ]

[RTAM &* Vel + RAM &* Omg]

# This looks like EoM1 except that the &* operator is now inside the definition of EoM2.

> EoM2[1, 1];

TAM &* Vel + TRAM &* Omg

> evalm(EoM2);

[TAM &* Vel + TRAM &* Omg]

[RTAM &* Vel + RAM &* Omg]

> evalm(EoM2[1, 1]);

[    Xud u + Xqd q    ]

[Yvd v + Ypd p + Yrd r]

[    Zwd w + Zqd q    ]

> evalm(EoM2[2, 1]);

[Kvd v + Kpd p + Krd r]

[Mud u + Mwd w + Mqd q]

[Nvd v + Npd p + Nrd r]

> evalm(EoM2[1, 1])[1, 1];

Xud u + Xqd q

# # Create matrix EoM by 3rd method

> MAM := blockmatrix(2, 2, [TAM, TRAM, RTAM, RAM]);

[Xud   0    0    0   Xqd   0 ]

[ 0   Yvd   0   Ypd   0   Yrd]

[ 0    0   Zwd   0   Zqd   0 ]

MAM := [                            ]

[ 0   Kvd   0   Kpd   0   Krd]

[Mud   0   Mwd   0   Mqd   0 ]

[ 0   Nvd   0   Npd   0   Nrd]

> MAM;

MAM

> evalm(MAM);

[Xud   0    0    0   Xqd   0 ]

[ 0   Yvd   0   Ypd   0   Yrd]

[ 0    0   Zwd   0   Zqd   0 ]

[ 0   Kvd   0   Kpd   0   Krd]

[Mud   0   Mwd   0   Mqd   0 ]

[ 0   Nvd   0   Npd   0   Nrd]

> S := stackmatrix(Vel, Omg);

[u]

[v]

[w]

S := [ ]

[p]

[q]

[r]

> EoM3 := `&*`(MAM, S);

EoM3 := MAM &* S

> EoM3;

MAM &* S

> evalm(EoM3);

[    Xud u + Xqd q    ]

[Yvd v + Ypd p + Yrd r]

[    Zwd w + Zqd q    ]

[Kvd v + Kpd p + Krd r]

[Mud u + Mwd w + Mqd q]

[Nvd v + Npd p + Nrd r]

>

﻿