MGMatrixExample.html

MotionGenesis input/output:


   (1) % MotionGenesis file: MGMatrixExample.txt
   (2) zeroMat23 = GetZeroMatrix( 2, 3 )
-> (3) zeroMat23 = [0, 0, 0;  0, 0, 0]

   (4) identity33 = GetIdentityMatrix( 3, 3 )
-> (5) identity33 = [1, 0, 0;  0, 1, 0;  0, 0, 1]

   (6) M = [1, 2;  3, sin(t)]   % 2 x 2 matrix.
-> (7) M = [1, 2;  3, sin(t)]

   (8) add = M + M
-> (9) add = [2, 4;  6, 2*sin(t)]

   (10) mult5 = 5 * M
-> (11) mult5 = [5, 10;  15, 5*sin(t)]

   (12) multM = M * M
-> (13) multM = [7, 2 + 2*sin(t);  3 + 3*sin(t), 6 + sin(t)^2]

   (14) divide =  M / 2
-> (15) divide = [0.5, 1;  1.5, 0.5*sin(t)]

   (16) transpose = GetTranspose( M )
-> (17) transpose = [1, 3;  2, sin(t)]

   (18) det = GetDeterminant( M )
-> (19) det = -6 + sin(t)

   (20) trace = GetTrace( M )
-> (21) trace = 1 + sin(t)

   (22) derivative = Dt( M )
-> (23) derivative = [0, 0;  0, cos(t)]

   (24) % Inverse(M) is a 2x2 matrix (displayed element by element below).
   (25) inv = GetInverse( M )
-> (26) inv[1,1] = sin(t)/(-6+sin(t))
-> (27) inv[1,2] = -2/(-6+sin(t))
-> (28) inv[2,1] = -3/(-6+sin(t))
-> (29) inv[2,2] = 1/(-6+sin(t))

   (30) eigValues = GetEigen( M )
-> (31) eigValues[1] = 0.5 + 0.5*sin(t) - 0.5*sqrt(24+(1+sin(t))^2-4*sin(t))
-> (32) eigValues[2] = 0.5 + 0.5*sin(t) + 0.5*sqrt(24+(1+sin(t))^2-4*sin(t))

   (33) element12 = M[ 1, 2 ]   % Element in 1st row, 2nd column.
-> (34) element12 = 2

   (35) element12 = GetElement( M, 1, 2 )
-> (36) element12 = 2

   (37) row2 = GetRow( M, 2 )            % Extract row 2 of M.
-> (38) row2 = [3, sin(t)]

   (39) col2 = GetCol( M, 2 )            % Extract column 2 of M.
-> (40) col2 = [2;  sin(t)]

   (41) extractRows = GetRow( M, 2, 1 )  % Extract rows 2 and 1 of M.
-> (42) extractRows = [3, sin(t);  1, 2]

   (43) colTwice = GetColumns( M, 2, 2 ) % Extract column 2 of M twice.
-> (44) colTwice = [2, 2;  sin(t), sin(t)]

   (45) MM = [ M,  M ]                   % 2 x 4 matrix.
-> (46) MM = [1, 2, 1, 2;  3, sin(t), 3, sin(t)]

   (47) Metc = [ M, 7*M, GetIdentityMatrix(2,2) ]
-> (48) Metc = [1, 2, 7, 14, 1, 0;  3, sin(t), 21, 7*sin(t), 0, 1]

   (49) extract = Metc[ 1:2, 3:6 ]       % Extract rows 1-2 and columns 3-6.
-> (50) extract = [7, 14, 1, 0;  21, 7*sin(t), 0, 1]

Saved by MotionGenesis 6.6 Professional user Motion Genesis LLC.
Portions (including program responses) are copyright (c) 2009-2026 Motion Genesis LLC.