matrixdemo - matrixdemo.nb 1 Matrices with Mathematica Demo...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Matrices with Mathematica Demo Vectors and Matrices ü Basic Operations In Mathematica vectors and matrices are represented as lists of numbers. For example, consider the two vectors In[1]:= u = 8 1, 0, 1 < Out[1]= 8 1, 0, 1 < In[2]:= v = 8 0, 1, 0 < Out[2]= 8 0, 1, 0 < When evaluating inner products of vectors in Mathematica it is not necessary to take the trans- pose of the first vector. Thus, taking the inner product of u and v is performed as follows. In[3]:= u.v Out[3]= 0 Therefore, u and v are orthogonal . Now let us consider the matrix from the first example in the section on systems of first-order differential equations. Essentially, a matrix is entered as a list of lists, or a list of vectors, with each row being entered as a vector. In[4]:= A = 88 0, 1, 1 < , 8 1, 0, 1 < , 8 1, 1, 0 << ; The semicolon at the end of the input line tells Mathematica to suppress its standard output. Instead, it is more convenient to output A in the usual matrix form as follows. In[5]:= MatrixForm @ A D Out[5]//MatrixForm= i k j j j j j j j 0 1 1 1 0 1 1 1 0 y { z z z z z z z matrixdemo.nb 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
We note that the coefficient matrix is real and symmetric ; therefore, it has linearly independent eigenvectors. However, before solving the example problem, we will illustrate some other matrix operations. The determinant of a square matrix is determined as follows. In[6]:= Det @ A D Out[6]= 2 Thus, A is nonsingular and invertible . The inverse is evaluated by the command (note that % represents the most recent output). In[7]:= Ainv = Inverse @ A D ; In[8]:= MatrixForm @ % D Out[8]//MatrixForm= i k j j j j j j j j j j j - 1 ÅÅÅ 2 1 ÅÅÅ 2 1 ÅÅÅ 2 1 ÅÅÅ 2 - 1 ÅÅÅ 2 1 ÅÅÅ 2 1 ÅÅÅ 2 1 ÅÅÅ 2 - 1 ÅÅÅ 2 y { z z z z z z z z z z z Matrix addition is performed just as you would think. In[9]:= A + A; In[10]:= MatrixForm @ % D Out[10]//MatrixForm= i k j j j j j j j 0 2 2 2 0 2 2 2 0 y { z z z z z z z Multiplication of a scalar times a matrix is also intuitive. In[11]:= 3 * A; In[12]:= MatrixForm @ % D Out[12]//MatrixForm= i k j j j j j j j 0 3 3 3 0 3 3 3 0 y { z z z z z z z Unlike most programming languages (C, Fortran, etc.), one can eliminate the '*' for multiplica- tion, so that Mathematica equations more closely resemble the way that you would write them on paper. For example, In[13]:= 3 A; matrixdemo.nb 2
Background image of page 2
In[14]:= MatrixForm @ % D Out[14]//MatrixForm= i k j j j j j j j 0 3 3 3 0 3 3 3 0 y { z z z z z z z Matrix multiplication is performed using the dot, the same command that is used to take the inner product of vectors. In[15]:= Ainv.A; In[16]:= MatrixForm @ % D Out[16]//MatrixForm= i k j j j j j j j 1 0 0 0 1 0 0 0 1 y { z z z z z z z Powers of matrices can be evaluated easily. For example, we raise A to the 5th power using. In[17]:= MatrixPower @ A, 5 D Out[17]= 88 10, 11, 11 < , 8 11, 10, 11 < , 8 11, 11, 10 << Because A is invertible, we can solve a system Az = v , where v is given above, as follows. In[18]:= z = Ainv.v Out[18]= 9 1 ÅÅÅÅ 2 , - 1 ÅÅÅÅ 2 , 1 ÅÅÅÅ 2 = Alternatively, Mathematica has a LinearSolve[] command that will do this for us.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

matrixdemo - matrixdemo.nb 1 Matrices with Mathematica Demo...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online