Preface


This is a tutorial made solely for the purpose of education and it was designed for students taking Applied Math 0340. It is primarily for students who have some experience using Mathematica. If you have never used Mathematica before and would like to learn more of the basics for this computer algebra system, it is strongly recommended looking at the APMA 0330 tutorial. As a friendly reminder, don'r forget to clear variables in use and/or the kernel.

Finally, the commands in this tutorial are all written in bold black font, while Mathematica output is in regular fonts. This means that you can copy and paste all comamnds into Mathematica, change the parameters and run them. You, as the user, are free to use the scripts to your needs for learning how to use the Mathematica program, and have the right to distribute this tutorial and refer to this tutorial as long as this tutorial is accredited appropriately.

Return to computing page for the first course APMA0330
Return to computing page for the second course APMA0340
Return to Mathematica tutorial for the first course APMA0330
Return to Mathematica tutorial for the second course APMA0340
Return to the main page for the course APMA0340
Return to the main page for the course APMA0330
Return to Part I of the course APMA0340

Basic Matrix Operations


Both a vector and a matrix can be multiplied by a scalar; with the operation being *. Matrices and vectors can be added or subtracted only when their dimensions are the same.

The dot product of any two vectors of the same dimension can be done with the dot operation given as Dot[vector 1, vector 2] or with use of a period “. “ .

{1,2,3}.{2,4,6}
28
Dot[{1,2,3},{3,2,1} ]
10

Now we start working with matrices. A period “.” can also be used for matrix multiplication between one matrix and a vector or two matrices. It is important to note that when doing matrix multiplication an (m x n) matrix can only be multiplied by an (n x s) where m, n, and s are whole numbers.

The cross product can be done on two vectors. It is important to note that the cross product is an operation that is only functional in three dimensions. The operation can be computed using the Cross[vector 1, vector 2] operation or by generating a cross product operator between two vectors by pressing [Esc] cross [Esc]. ([Esc] refers to the escape button)

To find the Euclidean length of a vector use the Norm[vector] operation. The command Norm[ ] also works for finding the norm of a complex number, where the imaginary part is represented by “I.”

Cross[{1,2,7}, {3,4,5}]
{-18,16,-2}
Norm[{5,2,9,7,3}]
2 Sqrt[42]

This definition can be extended to matrices:

Norm[{{0, 5}, {-1, 6}}]
Out[6]= Sqrt[31 + 6 Sqrt[26]]

Mathematica knows what vector should be used when a matrix is multiplied by a vector. For example,

A={{16,-9},{-12,13}};
v={1,2};
A.v
Out[3]= {-2,14}
v.A
Out[4]= {-8, 17}
This example shows that when a matrix is multiplied by a vector from right (this also means that a matrix is operated on a vector as a transformation), Mathematica treats it as a column-vector. When the vector is multiplied by a matrix from right, Mathematica treats the same vector as a row-vector. The following command finds the length (number of components) of a vector:
Length[v]
Out[5]= 2
Now we generate a special matrix, called zero matrix, whose all entries are zeroes.

Z23 = Table[0, {i, 2}, {j, 3}]          (* generates a list of zero values *)  
Out[1]= {{0, 0, 0}, {0, 0, 0}}
This matrix can be added (or subtracted from) to any matrix of the same dimensions (in our case, it is \( 2 \times 3 \) matrix)
A + Z23 == A
Out[2]= True
A == M
Out[6]= False

Example 2.1.1: Write the vector \( {\bf a}=2{\bf i}+3{\bf j}-4{\bf k} \) as the sum of two vectors, one parallel, and one perpendicular to the vector \( {\bf b}=2{\bf i}-{\bf j}-3{\bf k} .\)

We find the parallel vector:

a = {2, 3, -4}
b = {2, -1, -3}
madB2 = (b[[1]])^2 + (b[[2]])^2 + (b[[3]])^2
Aparallel = a.b/madB2*b
Out[4]= {13/7, -(13/14), -(39/14)}
To find the perpendicular vector, we type:
Aperpendicular = a - Aparallel
Out[5]= {1/7, 55/14, -(17/14)}
Another more stight forward way:
Aparallel = (a.b)*b/(b.b)
To verify the answer, we type:
Aparallel + Aperpendicular -a
Out[9]= 0

Example 2.1.2: Let a=<1,3,-4> and b=<-1,1,-2> be two vectors. Find \( {\bf a}\cdot ({\bf a}\times {\bf b}), \) where \( {\bf a}\cdot {\bf b} \) is dot product, and \( {\bf a}\times {\bf b} \) is cross product of two vectors. Input variables are vecors a and b. Function will calculate the cross product of a and b, and then calculate the dot product of that value and a. Notice that any input values for a and b will result in zero sum.

a={1,3,-4}
b={-1,1,-2}
c=a.Cross[a,b]
{0,0,0}
{-1,1,-2}
0

We don't know exactly who when the multiplication of matrices was invented. At least we know that the work of 1812 by Jacques Philippe Marie Binet (1786--1856) contains the definition of the product of matrices. Let A be a \( m \times n \) matrix and B be a \( n \times k \) matrix. Its product, a \( {\bf C} = {\bf A}\,{\bf B} \) is a \( m \times k \) matrix, in which the n entries across the rows of A are multiplied with the n entries down the columns of B:

\[ {\bf C} = \left[ c_{ij} \right] , \quad\mbox{where} \quad c_{ij}= \sum_{k=1}^n a_{ik}b_{kj} . \]

 

 

How to define Vectors

How to define Matrices

Basic Operations with Matrices

Linear Systems of Equations

Determinants and Inverse Matrices

Special Matrices

Eigenvalues and Eigenvectors

Generalized Eigenvectors

Diagonalization Procedure

Sylvester Formula

The Resolvent Method

Spectral Decomposition Method

Positive Matrices

Roots

Miscellaneous

 

Return to Mathematica page

Return to the main page (APMA0330)
Return to the Part 1 Matrix Algebra
Return to the Part 2 Linear Systems of Equations
Return to the Part 3 Linear Systems of Ordinary Differential Equations
Return to the Part 4 Non-linear Systems of Ordinary Differential Equations
Return to the Part 5 Numerical Methods
Return to the Part 6 Fourier Series
Return to the Part 7 Partial Differential Equations