MGMathExampleB.html  (MotionGenesis input/output).
   (1) % MotionGenesis file: MGMathExampleB.txt
   (2) % Copyright (c) 2009-2024 Motion Genesis LLC.  All rights reserved.
   (3) %--------------------------------------------------------------------
   (4) Variable   x', y'                 % Declare variables x, x', y, y'.
   (5) Constant   a, b, c, d             % Declare constants a, b, c, d.
   (6) SetImaginaryNumber( i )           % Declare i = sqrt(-1).
   (7) %--------------------------------------------------------------------
   (8) E = (x+2*y)^2 + 3*(7+x)*(x+y)     % Create an expression.
-> (9) E = (x+2*y)^2 + 3*(7+x)*(x+y)

   (10) Expand( E, 1:2 )                  % Clear parentheses.
-> (11) E = 21*x + 21*y + 4*x^2 + 4*y^2 + 7*x*y

   (12) Factor( E, x )                    % Factor on x.
-> (13) E = 21*y + 4*y^2 + 4*x*(5.25+x+1.75*y)

   (14) %--------------------------------------------------------------------
   (15) %   Mathematical commands.
   (16) Dy = D( E, y )                        % Partial derivative wrt. y
-> (17) Dy = 21 + 7*x + 8*y

   (18) Dt = Dt( E )                          % Total derivative wrt. t
-> (19) Dt = 21*y' + 8*y*y' + 7*(3+y)*x' + 7*x*(y'+1.142857*x')

   (20) Ty = GetTaylorSeries( x*cos(y), 0:7, x=0, y=0)
-> (21) Ty = 0.001388889*x*(720+30*y^4-360*y^2-y^6)

   (22) F = Evaluate( Ty, x=1, y=0.5 )        % Symbolic/numerical evaluation
-> (23) F = 0.8775825

   (24) Poly = GetPolynomial( [a,b,c], x )    % Creates a*x^2 +b*x +c
-> (25) Poly = c + b*x + a*x^2

   (26) Root1 = GetRoots( [1; 2; 3; 4] )      % Roots of x^3 + 2*x^2 + 3*x + 4 = 0
-> (27) Root1 = [-1.650629;  -0.1746854 - 1.546869*i;  -0.1746854 + 1.546869*i]

   (28) Root2 = GetQuadraticRoots( Poly = 0,  x )
-> (29) Root2[1] = -0.5*(b+sqrt(b^2-4*a*c))/a
-> (30) Root2[2] = -0.5*(b-sqrt(b^2-4*a*c))/a

   (31) %--------------------------------------------------------------------
   (32) %   Creating row or column matrices.
   (33) RowMatrix = [1, 2, 3, 4]     % Create a 1x4 matrix
-> (34) RowMatrix = [1, 2, 3, 4]

   (35) ColMatrix = [1; 2; 3; 4]     % Create a 4x1 matrix
-> (36) ColMatrix = [1;  2;  3;  4]

   (37) Zero[1] = a*x' + b*y' - 1    % Assign elements of column matrix
-> (38) Zero[1] = -1 + a*x' + b*y'

   (39) Zero[2] = c*x' + d*y' - Pi
-> (40) Zero[2] = -3.141593 + c*x' + d*y'

   (41) %--------------------------------------------------------------------
   (42) %   Solve a set of linear equations.
   (43) Solve( Zero = 0,  x', y' )
-> (44) x' = -(pi*b-d)/(a*d-b*c)
-> (45) y' = (pi*a-c)/(a*d-b*c)

   (46) %--------------------------------------------------------------------
   (47) %   Creating rectangular matrices.
   (48) M0 = [a, b;  c, 0]           % Create a 2x2 matrix
-> (49) M0 = [a, b;  c, 0]

   (50) M0[2,2] := d                 % Assign element of rectangular matrix
-> (51) M0[2,2] = d

   (52) M1 = [M0, [1,2; 3,4] ]       % Elements of matrices can be matrices
-> (53) M1 = [a, b, 1, 2;  c, d, 3, 4]

   (54) %--------------------------------------------------------------------
   (55) %   Matrix commands.
   (56) M2 = M0 + M0                 % Matrix addition
-> (57) M2 = [2*a, 2*b;  2*c, 2*d]

   (58) M3 = M0 * M0                 % Matrix multiplication
-> (59) M3 = [a^2 + b*c, b*(a+d);  c*(a+d), b*c + d^2]

   (60) M4 = GetTranspose( M0 )
-> (61) M4 = [a, c;  b, d]

   (62) M5 = GetInverse( M0 )
-> (63) M5[1,1] = d/(a*d-b*c)
-> (64) M5[1,2] = -b/(a*d-b*c)
-> (65) M5[2,1] = -c/(a*d-b*c)
-> (66) M5[2,2] = a/(a*d-b*c)

   (67) M6 = GetIdentityMatrix( 3 )
-> (68) M6 = [1, 0, 0;  0, 1, 0;  0, 0, 1]

   (69) M7 = GetZeroMatrix( 3, 3 )
-> (70) M7 = [0, 0, 0;  0, 0, 0;  0, 0, 0]

   (71) M8 = GetDiagonalMatrix(3,4, 5 )
-> (72) M8 = [5, 0, 0, 0;  0, 5, 0, 0;  0, 0, 5, 0]

   (73) C0 = GetColumns( M0, 1 )     % Returns column 1 of M0
-> (74) C0 = [a;  c]

   (75) R0 = GetRows( M0, 2, 1:2)    % Returns rows 2 and rows 1 through 2 of M0
-> (76) R0 = [c, d;  a, b;  c, d]

   (77) N1 = GetRows( M0 )           % Returns the number of rows in M0
-> (78) N1 = 2

   (79) det = GetDeterminant( M0 )
-> (80) det = a*d - b*c

   (81) M9 = Evaluate( M0,  a=1, b=2, c=3, d=4 )
-> (82) M9 = [1, 2;  3, 4]

   (83) Lambda = GetEigen( M9 )      % Eigenvalues
-> (84) Lambda = [-0.3722813;  5.372281]

   (85) EigValue = GetEigen( M9, EigVec)   % Eigenvalues/eigenvectors
-> (86) EigVec = [-0.8245648, -0.4159736;  0.5657675, -0.9093767]
-> (87) EigValue = [-0.3722813;  5.372281]

   (88) %--------------------------------------------------------------------
Saved by Motion Genesis LLC.  MotionGenesis 6.4 Professional.  Command names and syntax: Copyright (c) 2024 Motion Genesis LLC. All rights reserved.