Vec-mat
-
Upload
shivamj099 -
Category
Documents
-
view
218 -
download
0
Transcript of Vec-mat
-
8/13/2019 Vec-mat
1/27
Page 1of 2
Create a Matrix
LIST OF PRACTICALS BASED ON CSDC1-201 :LINEAR
ALGEBRA FOR COMPUTER SCIENCE
Practical Title
1. Create and transform vectors and matrices (the transpose vector (matrix)&conjugate transpose of a vector (matrix))
2. Solve system of Homogeneous and non homogeneous equations using Gausselimination, Cramers rule.
3. Generate the matrix into echelon form and find its rank.
4. Generate the LU decomposition of a matrix. Find cofactors, determinant,adjoint and inverse of a matrix
5. Generate basis of column space, null space, row space and left null space of amatrix space
6. Solution of system of equations using numerical methods
7. Check the linear dependency of vectors . Generate a linear combination ofgiven vectors of R
n/ matrices of same size and find the transition matrix of
given matrix space
8 Find the orthonormal basis of a given vector space using Gram-Schmidtorthogonalization process
9. Check the diagonalizable property of matrices and find thecorresponding eigen value and verify the Cayley- Hamilton theorem
10. Problems on LU factorization
11. Application of Linear algebra: Coding and decoding of messages using
non singular matrices. eg code Linear Algebra is a fun and then
decode it
12. Solve Linear programming problem (graphical and simplex method )
-
8/13/2019 Vec-mat
2/27
Page 2of 2
Matrices are represented in Mathematicawith lists. They can be entered directly with the { } notation,constructed from a formula, or imported from a data file. Mathematicaalso has commands for creatingdiagonal matrices, constant matrices, and other special matrix types.
A matrix can be entered directly with notation:
In[125]:=
Out[125]=
You can show the result in matrix notation withMatrixForm:In[126]:=
Out[126]//MatrixForm=
is another way of entering . It can be convenient to use it when is aformatting function.
This usesTableto create a grid of values in and :
In[127]:=
In[129]:=
// This is 4x5 matrix
Note that matrices in Mathematicaare not restricted to contain numbers; they can contain symbolic
entries such as formulas:
In[130]:=
This is 4 x 3 matrix with function x i+ xjand the initial value of i and j is 1
When you create a matrix and save it with an assignment, take care not to combine this with formatting
usingMatrixForm.Use parentheses:
In[132]:=
Out[132]//MatrixForm=
You can use in further calculations:
In[133]:=
Out[133]//MatrixForm=
Out[129]//MatrixForm=
Out[131]//MatrixForm=
http://input%28%27i_1%27%29/http://reference.wolfram.com/mathematica/ref/MatrixForm.htmlhttp://reference.wolfram.com/mathematica/ref/MatrixForm.htmlhttp://reference.wolfram.com/mathematica/ref/MatrixForm.htmlhttp://input%28%27i_3%27%29/http://reference.wolfram.com/mathematica/ref/Table.htmlhttp://reference.wolfram.com/mathematica/ref/Table.htmlhttp://reference.wolfram.com/mathematica/ref/Table.htmlhttp://input%28%27i_5%27%29/http://input%28%27i_7%27%29/http://input%28%27i_9%27%29/http://reference.wolfram.com/mathematica/ref/MatrixForm.htmlhttp://reference.wolfram.com/mathematica/ref/MatrixForm.htmlhttp://reference.wolfram.com/mathematica/ref/MatrixForm.htmlhttp://input%28%27i_11%27%29/http://input%28%27i_13%27%29/http://input%28%27i_13%27%29/http://input%28%27i_11%27%29/http://reference.wolfram.com/mathematica/ref/MatrixForm.htmlhttp://input%28%27i_9%27%29/http://input%28%27i_7%27%29/http://input%28%27i_5%27%29/http://reference.wolfram.com/mathematica/ref/Table.htmlhttp://input%28%27i_3%27%29/http://reference.wolfram.com/mathematica/ref/MatrixForm.htmlhttp://input%28%27i_1%27%29/ -
8/13/2019 Vec-mat
3/27
Page 3of 2
Suppose you do not use parentheses:
In[134]:=
Out[134]//MatrixForm=
Then will print like a matrix but will not work in calculations like a matrix. For example, the followingdoes not carry out matrix multiplication:
In[135]:=
Out[135]=
You can check the value of by usingFullForm:
In[11]:=
Out[11]//FullForm=
This shows that also includes the formatting wrapperMatrixForm,which stops it from working as a
matrix.
There are functions to create a variety of special types of matrices.
This creates a 45 matrix of real values that fall between and :
In[136]:=
Out[136]//MatrixForm=
This creates a matrix that only has nonzero entries on the diagonal:
In[137]:=
Out[137]//MatrixForm=
This creates a matrix whose entries are all the same:
In[138]:=
Out[138]//MatrixForm=
http://input%28%27i_15%27%29/http://input%28%27i_17%27%29/http://reference.wolfram.com/mathematica/ref/FullForm.htmlhttp://reference.wolfram.com/mathematica/ref/FullForm.htmlhttp://reference.wolfram.com/mathematica/ref/FullForm.htmlhttp://input%28%27i_19%27%29/http://reference.wolfram.com/mathematica/ref/MatrixForm.htmlhttp://reference.wolfram.com/mathematica/ref/MatrixForm.htmlhttp://reference.wolfram.com/mathematica/ref/MatrixForm.htmlhttp://input%28%27i_21%27%29/http://input%28%27i_23%27%29/http://input%28%27i_25%27%29/http://input%28%27i_25%27%29/http://input%28%27i_23%27%29/http://input%28%27i_21%27%29/http://reference.wolfram.com/mathematica/ref/MatrixForm.htmlhttp://input%28%27i_19%27%29/http://reference.wolfram.com/mathematica/ref/FullForm.htmlhttp://input%28%27i_17%27%29/http://input%28%27i_15%27%29/ -
8/13/2019 Vec-mat
4/27
Page 4of 2
This creates a 44 Hilbert matrix; each entry is of the form :
In[139]:=
Out[139]//MatrixForm=
Many linear algebra and other functions return matrices.Here, the QR decomposition of a random 33 matrix is calculated:
In[140]:=
This prints the Q matrix:
In[142]:=
Out[142]//MatrixForm=
When Mathematicafunctions return matrices they often use an optimized storage format called packedarrays.
You can apply many common operations in Mathematicato a list, and get back another list with the
function mapped onto each element. This also works for matrices, which are lists of lists.Here is a 22 matrix of squares:
In[143]:=
Out[144]//MatrixForm=
This appliesSqrtto each element of the matrix:
In[145]:=
Out[145]//MatrixForm=
This behavior ofSqrtis called listability, and it makes very readable and efficient code.
Vectors and Matrices
Vectors and matrices in Mathematicaare simply represented by lists and by lists of lists, respectively.
{a,b,c} vector
{{a,b},{c,d}}
matrix
The representation of vectors and matrices by lists.
http://input%28%27i_27%27%29/http://input%28%27i_29%27%29/http://input%28%27i_31%27%29/http://input%28%27i_33%27%29/http://reference.wolfram.com/mathematica/ref/Sqrt.htmlhttp://reference.wolfram.com/mathematica/ref/Sqrt.htmlhttp://reference.wolfram.com/mathematica/ref/Sqrt.htmlhttp://input%28%27i_35%27%29/http://reference.wolfram.com/mathematica/ref/Sqrt.htmlhttp://reference.wolfram.com/mathematica/ref/Sqrt.htmlhttp://reference.wolfram.com/mathematica/ref/Sqrt.htmlhttp://reference.wolfram.com/mathematica/ref/Sqrt.htmlhttp://input%28%27i_35%27%29/http://reference.wolfram.com/mathematica/ref/Sqrt.htmlhttp://input%28%27i_33%27%29/http://input%28%27i_31%27%29/http://input%28%27i_29%27%29/http://input%28%27i_27%27%29/ -
8/13/2019 Vec-mat
5/27
Page 5of 2
Because of the way Mathematicauses lists to represent vectors and matrices, you never have to
distinguish between "row" and "column" vectors.
Table[f,{i,n}] build a length-nvector by evaluating fwith
Array[a,n] build a length-nvector of the form
Range[n] create the list
Range[n1,n2] create the list
Range[n1,n2,dn] create the list
list[[i]]orPart[list,i] give the i element in the vector list
Length[list] give the number of elements in list
cv multiply a vector by a scalar
a.b dot product of two vectors
Cross[a,b] cross product of two vectors (also input as )
Norm[v] Euclidean norm of a vector
Functions for vectors.
Table[f,{i,m},{j,n}] build an mnmatrix by evaluating fwith iranging
from 1tomandjranging from 1to n
Array[a,{m,n}] build an mnmatrix with element
IdentityMatrix[n] generate an nnidentity matrix
DiagonalMatrix[list] generate a square matrix with the elements in liston the main
diagonal
list[[i]]orPart[list,i] give the i row in the matrix list
list[[All,j]]orPart[list,All,j] give thej column in the matrix list
list[[i,j]]orPart[list,i,j] give the element in the matrix list
Dimensions[list] give the dimensions of a matrix represented by list
Functions for matrices.
Column[list] display the elements of listin a column
MatrixForm[list] display listin matrix form
Formatting constructs for vectors and matrices.
This builds a 33 matrix with elements .
In[12]:=
Out[12]=
This displays in standard two-dimensional matrix format.
In[13]:=
Out[13]//MatrixForm=
This gives a vector with symbolic elements. You can use this in deriving general formulas that are valid with any choice o
vector components.
In[14]:=
https://reference.wolfram.com/mathematica/ref/Table.htmlhttps://reference.wolfram.com/mathematica/ref/Array.htmlhttps://reference.wolfram.com/mathematica/ref/Range.htmlhttps://reference.wolfram.com/mathematica/ref/Range.htmlhttps://reference.wolfram.com/mathematica/ref/Range.htmlhttps://reference.wolfram.com/mathematica/ref/Part.htmlhttps://reference.wolfram.com/mathematica/ref/Part.htmlhttps://reference.wolfram.com/mathematica/ref/Length.htmlhttps://reference.wolfram.com/mathematica/ref/Length.htmlhttps://reference.wolfram.com/mathematica/ref/Cross.htmlhttps://reference.wolfram.com/mathematica/ref/Norm.htmlhttps://reference.wolfram.com/mathematica/ref/Norm.htmlhttps://reference.wolfram.com/mathematica/ref/Table.htmlhttps://reference.wolfram.com/mathematica/ref/Array.htmlhttps://reference.wolfram.com/mathematica/ref/IdentityMatrix.htmlhttps://reference.wolfram.com/mathematica/ref/IdentityMatrix.htmlhttps://reference.wolfram.com/mathematica/ref/DiagonalMatrix.htmlhttps://reference.wolfram.com/mathematica/ref/DiagonalMatrix.htmlhttps://reference.wolfram.com/mathematica/ref/Part.htmlhttps://reference.wolfram.com/mathematica/ref/Part.htmlhttps://reference.wolfram.com/mathematica/ref/All.htmlhttps://reference.wolfram.com/mathematica/ref/All.htmlhttps://reference.wolfram.com/mathematica/ref/All.htmlhttps://reference.wolfram.com/mathematica/ref/Part.htmlhttps://reference.wolfram.com/mathematica/ref/Part.htmlhttps://reference.wolfram.com/mathematica/ref/Part.htmlhttps://reference.wolfram.com/mathematica/ref/All.htmlhttps://reference.wolfram.com/mathematica/ref/All.htmlhttps://reference.wolfram.com/mathematica/ref/All.htmlhttps://reference.wolfram.com/mathematica/ref/Part.htmlhttps://reference.wolfram.com/mathematica/ref/Part.htmlhttps://reference.wolfram.com/mathematica/ref/Dimensions.htmlhttps://reference.wolfram.com/mathematica/ref/Column.htmlhttps://reference.wolfram.com/mathematica/ref/Column.htmlhttps://reference.wolfram.com/mathematica/ref/MatrixForm.htmlhttp://input%28%27i_23%27%29/http://input%28%27i_25%27%29/http://input%28%27i_27%27%29/http://input%28%27i_27%27%29/http://input%28%27i_25%27%29/http://input%28%27i_23%27%29/https://reference.wolfram.com/mathematica/ref/MatrixForm.htmlhttps://reference.wolfram.com/mathematica/ref/Column.htmlhttps://reference.wolfram.com/mathematica/ref/Dimensions.htmlhttps://reference.wolfram.com/mathematica/ref/Part.htmlhttps://reference.wolfram.com/mathematica/ref/All.htmlhttps://reference.wolfram.com/mathematica/ref/Part.htmlhttps://reference.wolfram.com/mathematica/ref/All.htmlhttps://reference.wolfram.com/mathematica/ref/Part.htmlhttps://reference.wolfram.com/mathematica/ref/DiagonalMatrix.htmlhttps://reference.wolfram.com/mathematica/ref/IdentityMatrix.htmlhttps://reference.wolfram.com/mathematica/ref/Array.htmlhttps://reference.wolfram.com/mathematica/ref/Table.htmlhttps://reference.wolfram.com/mathematica/ref/Norm.htmlhttps://reference.wolfram.com/mathematica/ref/Cross.htmlhttps://reference.wolfram.com/mathematica/ref/Length.htmlhttps://reference.wolfram.com/mathematica/ref/Part.htmlhttps://reference.wolfram.com/mathematica/ref/Range.htmlhttps://reference.wolfram.com/mathematica/ref/Range.htmlhttps://reference.wolfram.com/mathematica/ref/Range.htmlhttps://reference.wolfram.com/mathematica/ref/Array.htmlhttps://reference.wolfram.com/mathematica/ref/Table.html -
8/13/2019 Vec-mat
6/27
Page 6of 2
Out[14]=
This gives a 32 matrix with symbolic elements."Building Lists from Functions"discusses how you can produce other
kinds of elements withArray.
In[15]:=
Out[15]=
Here are the dimensions of the matrix on the previous line.In[16]:=
Out[16]=
This generates a 33 diagonal matrix.
In[17]:=
Out[17]=
cm multiply a matrix by a scalar
a.b dot product of two matrices
Inverse[m] matrix inverse
MatrixPower[m,n] n power of a matrix
Det[m] determinant
Tr[m] trace
Transpose[m] transpose
Eigenvalues[m] eigenvalues
Eigenvectors[m] eigenvectors
Some mathematical operations on matrices.
Here is the 22 matrix of symbolic variables that was defined.
In[18]:=
Out[18]=
This gives its determinant.
In[19]:=
Out[19]=
Here is the transpose of .
In[20]:=
Out[20]=
This gives the inverse of in symbolic form.
In[21]:=
Out[21]=
Here is a 33 rational matrix.
In[22]:=
Out[22]=
This gives its inverse.
https://reference.wolfram.com/mathematica/tutorial/BuildingListsFromFunctions.htmlhttps://reference.wolfram.com/mathematica/tutorial/BuildingListsFromFunctions.htmlhttps://reference.wolfram.com/mathematica/tutorial/BuildingListsFromFunctions.htmlhttps://reference.wolfram.com/mathematica/ref/Array.htmlhttps://reference.wolfram.com/mathematica/ref/Array.htmlhttps://reference.wolfram.com/mathematica/ref/Array.htmlhttp://input%28%27i_29%27%29/http://input%28%27i_31%27%29/http://input%28%27i_33%27%29/https://reference.wolfram.com/mathematica/ref/Inverse.htmlhttps://reference.wolfram.com/mathematica/ref/MatrixPower.htmlhttps://reference.wolfram.com/mathematica/ref/MatrixPower.htmlhttps://reference.wolfram.com/mathematica/ref/Det.htmlhttps://reference.wolfram.com/mathematica/ref/Det.htmlhttps://reference.wolfram.com/mathematica/ref/Tr.htmlhttps://reference.wolfram.com/mathematica/ref/Transpose.htmlhttps://reference.wolfram.com/mathematica/ref/Transpose.htmlhttps://reference.wolfram.com/mathematica/ref/Eigenvalues.htmlhttps://reference.wolfram.com/mathematica/ref/Eigenvalues.htmlhttps://reference.wolfram.com/mathematica/ref/Eigenvectors.htmlhttp://input%28%27i_35%27%29/http://input%28%27i_37%27%29/http://input%28%27i_39%27%29/http://input%28%27i_41%27%29/http://input%28%27i_43%27%29/http://input%28%27i_43%27%29/http://input%28%27i_41%27%29/http://input%28%27i_39%27%29/http://input%28%27i_37%27%29/http://input%28%27i_35%27%29/https://reference.wolfram.com/mathematica/ref/Eigenvectors.htmlhttps://reference.wolfram.com/mathematica/ref/Eigenvalues.htmlhttps://reference.wolfram.com/mathematica/ref/Transpose.htmlhttps://reference.wolfram.com/mathematica/ref/Tr.htmlhttps://reference.wolfram.com/mathematica/ref/Det.htmlhttps://reference.wolfram.com/mathematica/ref/MatrixPower.htmlhttps://reference.wolfram.com/mathematica/ref/Inverse.htmlhttp://input%28%27i_33%27%29/http://input%28%27i_31%27%29/http://input%28%27i_29%27%29/https://reference.wolfram.com/mathematica/ref/Array.htmlhttps://reference.wolfram.com/mathematica/tutorial/BuildingListsFromFunctions.html -
8/13/2019 Vec-mat
7/27
Page 7of 2
In[23]:=
Out[23]=
Taking the dot product of the inverse with the original matrix gives the identity matrix.
In[24]:=
Out[24]=
Here is a 33 matrix.
In[25]:=
Out[25]=
Eigenvaluesgives the eigenvalues of the matrix.
In[26]:=
Out[26]=
This gives a numerical approximation to the matrix.
In[27]:=
Out[27]=
Here are numerical approximations to the eigenvalues.
In[28]:=
Out[28]=
ConjugateTranspose
The conjugate transpose of an matrix is the matrix defined by
(
where denotes thetransposeof the matrix and denotes theconjugate matrix.In all common spaces (i.e., separableHilberspaces), the conjugate and transpose operations commute, so
(
The symbol (where the "H" stands for "Hermitian") gives official recognition to the fact that forcomplex matrices,it is almostalways the case that the combined operation of taking the transpose and complex conjugate arises in physical or computation
contexts and virtually never thetransposein isolation (Strang 1988, pp. 220-221).
The conjugate transpose of a matrix is implemented inMathematicaasConjugateTranspose[A].
The conjugate transpose is also known as the adjoint matrix, adjugate matrix, Hermitian adjoint, or Hermitian transpose (Strang
1988, p. 221). Unfortunately, several different notations are in use as summarized in the following table. While the notation is
universally used in quantum field theory, is commonly used in linear algebra. Note that because is sometimes used to denothecomplex conjugate,special care must be taken not to confuse notations from different sources.
http://input%28%27i_45%27%29/http://input%28%27i_47%27%29/http://input%28%27i_49%27%29/https://reference.wolfram.com/mathematica/ref/Eigenvalues.htmlhttps://reference.wolfram.com/mathematica/ref/Eigenvalues.htmlhttp://input%28%27i_51%27%29/http://input%28%27i_53%27%29/http://input%28%27i_55%27%29/http://mathworld.wolfram.com/Matrix.htmlhttp://mathworld.wolfram.com/Matrix.htmlhttp://mathworld.wolfram.com/Transpose.htmlhttp://mathworld.wolfram.com/Transpose.htmlhttp://mathworld.wolfram.com/Transpose.htmlhttp://mathworld.wolfram.com/ConjugateMatrix.htmlhttp://mathworld.wolfram.com/ConjugateMatrix.htmlhttp://mathworld.wolfram.com/ConjugateMatrix.htmlhttp://mathworld.wolfram.com/HilbertSpace.htmlhttp://mathworld.wolfram.com/HilbertSpace.htmlhttp://mathworld.wolfram.com/HilbertSpace.htmlhttp://mathworld.wolfram.com/HilbertSpace.htmlhttp://mathworld.wolfram.com/ComplexMatrix.htmlhttp://mathworld.wolfram.com/ComplexMatrix.htmlhttp://mathworld.wolfram.com/ComplexMatrix.htmlhttp://mathworld.wolfram.com/Transpose.htmlhttp://mathworld.wolfram.com/Transpose.htmlhttp://mathworld.wolfram.com/Transpose.htmlhttp://www.wolfram.com/mathematica/http://www.wolfram.com/mathematica/http://www.wolfram.com/mathematica/http://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://mathworld.wolfram.com/ComplexConjugate.htmlhttp://mathworld.wolfram.com/ComplexConjugate.htmlhttp://mathworld.wolfram.com/ComplexConjugate.htmlhttp://mathworld.wolfram.com/ComplexConjugate.htmlhttp://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://www.wolfram.com/mathematica/http://mathworld.wolfram.com/Transpose.htmlhttp://mathworld.wolfram.com/ComplexMatrix.htmlhttp://mathworld.wolfram.com/HilbertSpace.htmlhttp://mathworld.wolfram.com/HilbertSpace.htmlhttp://mathworld.wolfram.com/ConjugateMatrix.htmlhttp://mathworld.wolfram.com/Transpose.htmlhttp://mathworld.wolfram.com/Matrix.htmlhttp://input%28%27i_55%27%29/http://input%28%27i_53%27%29/http://input%28%27i_51%27%29/https://reference.wolfram.com/mathematica/ref/Eigenvalues.htmlhttp://input%28%27i_49%27%29/http://input%28%27i_47%27%29/http://input%28%27i_45%27%29/ -
8/13/2019 Vec-mat
8/27
Page 8of 2
notation references
This work; Golub and van Loan (1996, p. 14), Strang (1988, p. 220)
Courant and Hilbert (1989, p. 9), Lancaster and Tismenetsky (1984), Meyer (2000)
Arfken (1985, p. 210), Weinberg (1995, p. xxv)
If amatrixis equal to its own conjugate transpose, it is said to beself-adjointand is called aHermitian.
Conjugate transpose of a complex-valued matrix:
In[1]:=
In[2]:=
Out[2]//MatrixForm=
In[3]:=
Out[3]//MatrixForm=
Enter using EscctEsc :
In[1]:=
Out[1]=
Conjugate transpose a sparse array:
In[1]:=
Out[1]=
In[2]:=
Out[2]//MatrixForm=
The conjugate transpose is sparse:
In[3]:=
Out[3]=
In[4]:=
Out[4]//MatrixForm=
http://mathworld.wolfram.com/Matrix.htmlhttp://mathworld.wolfram.com/Matrix.htmlhttp://mathworld.wolfram.com/Matrix.htmlhttp://mathworld.wolfram.com/Self-AdjointMatrix.htmlhttp://mathworld.wolfram.com/Self-AdjointMatrix.htmlhttp://mathworld.wolfram.com/Self-AdjointMatrix.htmlhttp://mathworld.wolfram.com/HermitianMatrix.htmlhttp://mathworld.wolfram.com/HermitianMatrix.htmlhttp://mathworld.wolfram.com/HermitianMatrix.htmlhttp://input%28%27i_1%27%29/http://input%28%27i_3%27%29/http://input%28%27i_5%27%29/http://input%28%27i_7%27%29/http://input%28%27i_9%27%29/http://input%28%27i_11%27%29/http://input%28%27i_13%27%29/http://input%28%27i_15%27%29/http://input%28%27i_15%27%29/http://input%28%27i_13%27%29/http://input%28%27i_11%27%29/http://input%28%27i_9%27%29/http://input%28%27i_7%27%29/http://input%28%27i_5%27%29/http://input%28%27i_3%27%29/http://input%28%27i_1%27%29/http://mathworld.wolfram.com/HermitianMatrix.htmlhttp://mathworld.wolfram.com/Self-AdjointMatrix.htmlhttp://mathworld.wolfram.com/Matrix.html -
8/13/2019 Vec-mat
9/27
Page 9of 2
ConjugateTransposeworks for symbolic matrices:
In[1]:=
Out[1]=
ComplexExpandassumes all variables are real:
In[2]:=
Out[2]=
Generalizations & Extensions (1)ConjugateTransposeworks similarly toTransposefor tensors:
In[1]:=
Out[1]=
Conjugate and transpose the first two dimensions:
In[2]:=
Out[2]=
Conjugate and transpose the first and third dimensions:
In[3]:=
Out[3]=
Applications (1)is a random complex matrix:
In[1]:=
Find theQRDecompositionof :
In[2]:=
is unitary, so its inverse is
http://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://input%28%27i_17%27%29/http://reference.wolfram.com/mathematica/ref/ComplexExpand.htmlhttp://reference.wolfram.com/mathematica/ref/ComplexExpand.htmlhttp://input%28%27i_19%27%29/http://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://reference.wolfram.com/mathematica/ref/Transpose.htmlhttp://reference.wolfram.com/mathematica/ref/Transpose.htmlhttp://reference.wolfram.com/mathematica/ref/Transpose.htmlhttp://input%28%27i_21%27%29/http://input%28%27i_23%27%29/http://input%28%27i_25%27%29/http://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://input%28%27i_27%27%29/http://reference.wolfram.com/mathematica/ref/QRDecomposition.htmlhttp://reference.wolfram.com/mathematica/ref/QRDecomposition.htmlhttp://reference.wolfram.com/mathematica/ref/QRDecomposition.htmlhttp://input%28%27i_29%27%29/http://input%28%27i_29%27%29/http://reference.wolfram.com/mathematica/ref/QRDecomposition.htmlhttp://input%28%27i_27%27%29/http://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://input%28%27i_25%27%29/http://input%28%27i_23%27%29/http://input%28%27i_21%27%29/http://reference.wolfram.com/mathematica/ref/Transpose.htmlhttp://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://input%28%27i_19%27%29/http://reference.wolfram.com/mathematica/ref/ComplexExpand.htmlhttp://input%28%27i_17%27%29/http://reference.wolfram.com/mathematica/ref/ConjugateTranspose.html -
8/13/2019 Vec-mat
10/27
Page 10of 2
In[3]:=
Out[3]=
Reconstruct from the decomposition:
In[4]:=
Out[4]=
Properties & Relations (2)ConjugateTranspose[m]is equivalent toConjugate[Transpose[m]]:
In[1]:=
In[2]:=
Out[2]=
The product of a matrix and its conjugate transpose is Hermitian:
In[1]:=
is the matrix product of and .
In[2]:=
so is Hermitian:
In[3]:=
Out[3]=
Entering Tables and MatricesThe Mathematicafront end provides anInsertTable/Matrixsubmenu for creating and editing arrayswith any specified number of rows and columns. Once you have such an array, you can edit it to fill inwhatever elements you want.
Mathematicatreats an array like this as a matrix represented by a list of lists.
In[1]:=
Out[1]=
Putting parentheses around the array makes it look more like a matrix, but does not affect its interpretation.
In[2]:=
Out[2]=
UsingMatrixFormtells Mathematicato display the result of theTransposeas a matrix.
In[3]:=
Out[3]//MatrixForm=
http://input%28%27i_31%27%29/http://input%28%27i_33%27%29/http://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://reference.wolfram.com/mathematica/ref/Conjugate.htmlhttp://reference.wolfram.com/mathematica/ref/Conjugate.htmlhttp://reference.wolfram.com/mathematica/ref/Conjugate.htmlhttp://reference.wolfram.com/mathematica/ref/Transpose.htmlhttp://reference.wolfram.com/mathematica/ref/Transpose.htmlhttp://input%28%27i_35%27%29/http://input%28%27i_37%27%29/http://input%28%27i_39%27%29/http://input%28%27i_41%27%29/http://input%28%27i_43%27%29/http://reference.wolfram.com/mathematica/guide/InsertMenu.htmlhttp://reference.wolfram.com/mathematica/guide/InsertMenu.htmlhttp://reference.wolfram.com/mathematica/guide/InsertMenu.htmlhttp://reference.wolfram.com/mathematica/ref/menuitem/TableMatrix.htmlhttp://reference.wolfram.com/mathematica/ref/menuitem/TableMatrix.htmlhttp://reference.wolfram.com/mathematica/ref/menuitem/TableMatrix.htmlhttp://input%28%27i_1%27%29/http://input%28%27i_3%27%29/http://reference.wolfram.com/mathematica/ref/MatrixForm.htmlhttp://reference.wolfram.com/mathematica/ref/MatrixForm.htmlhttp://reference.wolfram.com/mathematica/ref/MatrixForm.htmlhttp://reference.wolfram.com/mathematica/ref/Transpose.htmlhttp://reference.wolfram.com/mathematica/ref/Transpose.htmlhttp://reference.wolfram.com/mathematica/ref/Transpose.htmlhttp://input%28%27i_5%27%29/http://input%28%27i_5%27%29/http://reference.wolfram.com/mathematica/ref/Transpose.htmlhttp://reference.wolfram.com/mathematica/ref/MatrixForm.htmlhttp://input%28%27i_3%27%29/http://input%28%27i_1%27%29/http://reference.wolfram.com/mathematica/ref/menuitem/TableMatrix.htmlhttp://reference.wolfram.com/mathematica/guide/InsertMenu.htmlhttp://input%28%27i_43%27%29/http://input%28%27i_41%27%29/http://input%28%27i_39%27%29/http://input%28%27i_37%27%29/http://input%28%27i_35%27%29/http://reference.wolfram.com/mathematica/ref/Transpose.htmlhttp://reference.wolfram.com/mathematica/ref/Conjugate.htmlhttp://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://reference.wolfram.com/mathematica/ref/ConjugateTranspose.htmlhttp://input%28%27i_33%27%29/http://input%28%27i_31%27%29/ -
8/13/2019 Vec-mat
11/27
Page 11of 2
Complex Matrix
Amatrix whose elements may containcomplex numbers.
Thematrix product of two complex matrices is given by
(
where
Hadamard (1893) proved that thedeterminantof any complex matrix with entries in the closedunit disk satisfies
(1
(Hadamard's maximum determinant problem),with equality attained by theVandermonde matrixof the roots of unity(Faddeev and Sominskii 1965, p. 331; Brenner 1972). The first few values
for , 2, ... are 1, 2, , 16, , 216, ....
Determining the Eigenvalues of a Matrix
Studying the maximum possible eigenvalue norms for random complex matrices is computationally intractable.
Although average properties of the distribution of can be determined, finding the maximum value corresponds todetermining if the set of matrices contains asingular matrix,which has been proven to be anNP-complete
problem(Poljak and Rohn 1993, Kaltofen 2000). The above plots show the distributions for , , andmatrix eigenvalue norms for elements uniformly distributed inside the unit disk . Similar plots are obtained for
elements uniformly distributed inside . The exact distribution of eigenvalues for complex matrices wiboth real and imaginary parts distributed as independent standard normal variates is given by Ginibre (1965), Hwang
(1986), and Mehta (1991).
Given a square matrixA, the condition that characterizes an eigenvalue, , is the existence of a nonzerovector xsuch
thatAx= x; this equation can be rewritten as follows:
http://mathworld.wolfram.com/Matrix.htmlhttp://mathworld.wolfram.com/ComplexNumber.htmlhttp://mathworld.wolfram.com/MatrixProduct.htmlhttp://mathworld.wolfram.com/Determinant.htmlhttp://mathworld.wolfram.com/Determinant.htmlhttp://mathworld.wolfram.com/Determinant.htmlhttp://mathworld.wolfram.com/UnitDisk.htmlhttp://mathworld.wolfram.com/UnitDisk.htmlhttp://mathworld.wolfram.com/UnitDisk.htmlhttp://mathworld.wolfram.com/HadamardsMaximumDeterminantProblem.htmlhttp://mathworld.wolfram.com/HadamardsMaximumDeterminantProblem.htmlhttp://mathworld.wolfram.com/HadamardsMaximumDeterminantProblem.htmlhttp://mathworld.wolfram.com/VandermondeMatrix.htmlhttp://mathworld.wolfram.com/VandermondeMatrix.htmlhttp://mathworld.wolfram.com/VandermondeMatrix.htmlhttp://mathworld.wolfram.com/RootofUnity.htmlhttp://mathworld.wolfram.com/RootofUnity.htmlhttp://mathworld.wolfram.com/SingularMatrix.htmlhttp://mathworld.wolfram.com/SingularMatrix.htmlhttp://mathworld.wolfram.com/SingularMatrix.htmlhttp://mathworld.wolfram.com/NP-CompleteProblem.htmlhttp://mathworld.wolfram.com/NP-CompleteProblem.htmlhttp://mathworld.wolfram.com/NP-CompleteProblem.htmlhttp://mathworld.wolfram.com/NP-CompleteProblem.htmlhttp://mathworld.wolfram.com/NP-CompleteProblem.htmlhttp://mathworld.wolfram.com/NP-CompleteProblem.htmlhttp://mathworld.wolfram.com/SingularMatrix.htmlhttp://mathworld.wolfram.com/RootofUnity.htmlhttp://mathworld.wolfram.com/VandermondeMatrix.htmlhttp://mathworld.wolfram.com/HadamardsMaximumDeterminantProblem.htmlhttp://mathworld.wolfram.com/UnitDisk.htmlhttp://mathworld.wolfram.com/Determinant.htmlhttp://mathworld.wolfram.com/MatrixProduct.htmlhttp://mathworld.wolfram.com/ComplexNumber.htmlhttp://mathworld.wolfram.com/Matrix.html -
8/13/2019 Vec-mat
12/27
Page 12of 2
This final form of the equation makes it clear that xis the solution of a square, homogeneous system.
Ifnonzerosolutions are desired, then the determinant of the coefficient matrixwhich in this case isA Imust be
zero; if not, then the system possesses only the trivial solution x = 0. Since eigenvectors are, by definition, nonzero, in
order for xto be an eigenvector of a matrixA, must be chosen so that
When the determinant ofA Iis written out, the resulting expression is a monic polynomial in .
[A monicpolynomial is one in which the coefficient of the leading (the highestdegree) term is 1.] It is called
the characteristic polynomialofAand will be of degree nifAis n x n. The zeros of the characteristic polynomial
ofAthat is, the solutions of the characteristic equation, det(A I) = 0are the eigenvalues ofA.
Gaussian elimination is usually carried out using matrices. This method reduces the effort in findingthe solutions by eliminating the need to explicitly write the variables at each step. The previous
example will be redone using matrices.
Example 2: Solve this system:
The first step is to write the coefficients of the unknowns in a matrix:
This is called the coefficient matrixof the system. Next, the coefficient matrix is augmented by writing the constants
that appear on the righthand sides of the equations as an additional column:
This is called the augmented matrix, and each row corresponds to an equation in the given system. The first row, r1(1, 1, 3), corresponds to the first equation, 1x+ 1y= 3, and the second row, r2= (3, 2, 4), corresponds to the secondequation, 3x 2y= 4. You may choose to include a vertical lineas shown aboveto separate the coefficients of th
unknowns from the extra column representing the constants.
Now, the counterpart of eliminating a variable from an equation in the system is changing one of the entries in the
coefficient matrix to zero. Likewise, the counterpart of adding a multiple of one equation to another is adding amultiple of one row to another row. Adding 3 times the first row of the augmented matrix to the second row yields
-
8/13/2019 Vec-mat
13/27
Page 13of 2
The new second row translates into 5y= 5, which meansy= 1. Backsubstitution into the first row (that is, into theequation that represents the first row) yieldsx= 2 and, therefore, the solution to the system: (x, y) = (2, 1).
Gaussian elimination can be summarized as follows. Given a linear system expressed in matrix form, Ax = b, firstwrite down the corresponding augmented matrix:
Then, perform a sequence of elementary row operations, which are any of the following:
Type 1. Interchange any two rows.
Type 2. Multiply a row by a nonzero constant.
Type 3. Add a multiple of one row to another row.
The goal of these operations is to transformor reducethe original augmented matrix into one of the form
whereA is upper triangular (aij = 0 fori > j), any zero rows appear at the bottom of the matrix, and the first nonzeroentry in any row is to the right of the first nonzero entry in any higher row; such a matrix is said to be in echelonformThe solutions of the system represented by the simpler augmented matrix, [ A |b], can be found by inspectoin of the
bottom rows and backsubstitution into the higher rows. Since elementary row operations do not change the solutions
of the system, the vectors xwhich satisfy the simpler systemAx= b are precisely those that satisfy the originalsystem,Ax= b.Example 3: Solve the following system using Gaussian elimination:
The augmented matrix which represents this system is
The first goal is to produce zeros below the first entry in the first column, which translates into eliminatingthe first variable,x, from the second and third equations. The row operations which accomplish this are as
follows:
-
8/13/2019 Vec-mat
14/27
Page 14of 2
The second goal is to produce a zero below the second entry in the second column, which translates intoeliminating the second variable,y, from the third equation. One way to accomplish this would be to add 1/
times the second row to the third row. However, to avoid fractions, there is another option: first interchange
rows two and three. Interchanging two rows merely interchanges the equations, which clearly will not alterthe solution of the system:
Now, add 5 times the second row to the third row:
Since the coefficient matrix has been transformed into echelon form, the forward part of Gaussian
elimination is complete. What remains now is to use the third row to evaluate the third unknown, then to
backsubstitute into the second row to evaluate the second unknown, and, finally, to backsubstitute into thefirst row to evaluate the first unknwon.
The third row of the final matrix translates into 10z= 10, which givesz= 1. Backsubstitution of this valueinto the second row, which represents the equationy 3z= 1, yieldsy= 2. Backsubstitution of both these
values into the first row, which represents the equationx 2y + z= 0, givesx= 3. The solution of thissystem is therefore (x, y, z) = (3, 2, 1).
Example 4: Solve the following system using Gaussian elimination:
For this system, the augmented matrix (vertical line omitted) is
-
8/13/2019 Vec-mat
15/27
Page 15of 2
First, multiply row 1 by 1/2:
Now, adding 1 times the first row to the second row yields zeros below the first entry in the first column:
Interchanging the second and third rows then gives the desired uppertriangular coefficient matrix:
The third row now saysz= 4. Backsubstituting this value into the second row givesy= 1, and
backsubstitution of both these values into the first row yieldsx= 2. The solution of this system is therefor(x, y, z) = (2, 1, 4).
GaussJordan elimination. Gaussian elimination proceeds by performing elementary row operations toproduce zeros below the diagonal of the coefficient matrix to reduce it to echelon form.(Recall that amatrixA = [aij] is in echelon form whenaij= 0 fori > j, any zero rows appear at the bottom of the matrix,and the first nonzero entry in any row is to the right of the first nonzero entry in any higher row.) Once this i
done, inspection of the bottom row(s) and backsubstitution into the upper rows determine the values of theunknowns.
However, it is possible to reduce (or eliminate entirely) the computations involved in backsubstitution by
performing additional row operations to transform the matrix from echelon form to reduced echelonform.
matrix is in reduced echelon form when, in addition to being in echelon form, each column that contians anonzero entry (usually made to be 1) has zeros not just below that entry but also above that entry. Loosely
speaking, Gaussian elimination works from the top down, to produce a matrix in echelon form,
whereas GaussJordan eliminationcontinues where Gaussian left off by then working from the bottom upto produce a matrix in reduced echelon form. The technique will be illustrated in the following example.Example 5: The height,y, of an object thrown into the air is known to be given by a quadratic function
of t(time) of the formy= at2+ bt+ c. If the object is at heighty= 23/4 at time t= 1/2, aty= 7 at time t= 1
and aty= 2 at t= 2, determine the coefficients a, b, and c.
Since t= 1/2 givesy= 23/4
-
8/13/2019 Vec-mat
16/27
Page 16of 2
while the other two conditions,y(t= 1) = 7 andy(t= 2) = 2, give the following equations for a, b, and c:
Therefore, the goal is solve the system
The augmented matrix for this system is reduced as follows:
At this point, the forward part of Gaussian elimination is finished, since the coefficient matrix has been
reduced to echelon form. However, to illustrate GaussJordan elimination, the following additionalelementary row operations are performed:
This final matrix immediately gives the solution: a= 5,b= 10, and c= 2.
Example 6: Solve the following system using Gaussian elimination:
-
8/13/2019 Vec-mat
17/27
Page 17of 2
The augmented matrix for this system is
Multiples of the first row are added to the other rows to produce zeros below the first entry in the first
column:
Next, 1 times the second row is added to the third row:
The third row now says 0x+ 0y+ 0z= 1, an equation that cannot be satisfied by any values ofx, y, andz.The process stops: this system has no solutions.
The previous example shows how Gaussian elimination reveals an inconsistent system. A slight alteration o
that system (for example, changing the constant term 7 in the third equation to a 6) will illustrate a
system with infinitely many solutions.
Example 7: Solve the following system using Gaussian elimination:
The same operations applied to the augment matrix of the system in Example 6 are applied to the augmented
matrix for the present system:
-
8/13/2019 Vec-mat
18/27
Page 18of 2
Here, the third row translates into 0x+ 0y+ 0z= 0, an equation which is satisfied by any x, y, andz. Since
this offer no constraint on the unknowns, there are not three conditions on the unknowns, only two(represented by the two nonzero rows in the final augmented matrix). Since there are 3 unknowns but only 2
constrants, 3 2 =1 of the unknowns, zsay, is arbitrary; this is called a free variable. Letz = t, where tis
any real number. Backsubstitution ofz = tinto the second row (y+ 5z= 6) gives
Back substitutingz = tandy= 6 + 5 tinto the first row (x + y 3z= 4) determinesx:
Therefore, every solution of the system has the form
where tis any real number. There are infinitely many solutions, since every real value of tgives a differentparticular solution. For example, choosing t= 1 gives (x, y, z) = (4, 11, 1), whilet= 3 gives (x, y, z) = (4,
9, 3), and so on. Geometrically, this system represents three planes inR3that intersect in a line, and (*) i
a parametric equation for this line.
Example 7 provided an illustration of a system with infinitely many solutions, how this case arises, and howthe solution is written. Every linear system that possesses infinitely many solutions must contain at least one
arbitrary parameter(free variable). Once the augmented matrix has been reduced to echelon form, the
number of free variables is equal to the total number of unknowns minus the number of nonzero rows:
This agrees with Theorem B above, which states that a linear system with fewer equations than unknowns, iconsistent, has infinitely many solutions. The condition fewer equations than unknowns means that the
number of rows in the coefficient matrix is less than the number of unknowns. Therefore, the boxed equatio
above implies that there must be at least one free variable. Since such a variable can, by definition, take on
infinitely many values, the system will have infinitely many solutions.
-
8/13/2019 Vec-mat
19/27
Page 19of 2
Example 8: Find all solutions to the system
First, note that there are four unknwons, but only thre equations. Therefore, if the system is consistent, it isguaranteed to have infinitely many solutions, a condition characterized by at least one parameter in the
general solution. After the corresponding augmented matrix is constructed, Gaussian elimination yields
The fact that only two nonzero rows remain in the echelon form of the augmented matrix means that 4 2 =
2 of the variables are free:
Therefore, selectingyandzas the free variables, lety= t1andz= t2. The second row of the reducedaugmented matrix implies
and the first row then gives
Thus, the solutions of the system have the form
-
8/13/2019 Vec-mat
20/27
Page 20of 2
where t1t2are allowed to take on any real values.
Example 9: Let b= ( b1, b2, b3)Tand letAbe the matrix
For what values of b1, b2, and b3will the systemAx= bbe consistent?
The augmented matrix for the systemAx= breads
which Gaussian eliminatin reduces as follows:
The bottom row now implies that b1+ 3 b2+ b3must be zero if this system is to be consistent. Therefore,the given system has solutins (infinitely many, in fact) only for those column vectors b= ( b1, b2, b3)
Tfor
which b1+ 3 b2+ b3= 0.
Example 10: Solve the following system (compare to Example 12):
A system such as this one, where the constant term on the righthand side of everyequation is 0, is calleda homogeneoussystem. In matrix form it readsAx= 0. Since every homogeneous system is consistent
because x= 0is always a solutiona homogeneous system has eithe exactly one solution
(the trivialsolution, x=0) or infiitely many. The rowreduction of the coefficient matrix for this system hasalready been performed in Example 12. It is not necessary to explicitly augment the coefficient matrix with
the column b = 0, since no elementary row operation can affect these zeros. That is, ifA is an echelon form
ofA, then elementary row operations will transform [A| 0] into [A|0]. From the results of Example 12,
-
8/13/2019 Vec-mat
21/27
Page 21of 2
Since the last row again implies thatzcan be taken as a free variable, letz= t, where tis any real number.
Backsubstitution ofz= tinto the second row (y+ 5z= 0) gives
and backsubstitution ofz= tandy= 5 tinto the first row (x+y 3z= 0) determinesx:
Therefore, every solution of this system has the form (x, y, z) = (2t, 5 t, t), where tis any real number.
There are infinitely many solutins, since every real value of tgives a unique particular solution.Note carefully the differnece between the set of solutions to the system in Example 12 and the one here.
Although both had the same coefficient matrixA, the system in Example 12 was nonhomogeneous (Ax= bwhere b0), while the one here is the corresponding homogeneous system,Ax= 0. Placing their solutionsside by side,
general solution to Ax = 0: (x, y, z) = (2t, 5 t, t)
general solution to Ax = b: (x, y, z) = (2t, 5 t, t) + (2, 6, 0)
illustrates an important fact:
Theorem C. The general solutions to a consistent nonhomogeneous lienar system,Ax= b, is equal to the
general solution of the corresponding homogeneous system,Ax= 0, plus a particular solution of the
nonhomogeneous system. That is, if x= xhrepresents the general solution ofAx= 0, then x= xh+ x
represents the general solution ofAx+ b, where x is any particular soltion of the (consistent)nonhomogeneous systemAx= b.
[Technical note: Theorem C, which concerns a linear system, has a counterpart in the theory of linear
diffrential equations. LetLbe a linear differential operator; then the general solution of a solvable
nonhomogeneous linear differential equation,L(y)= d(where d0), is equal to the general solution of thecorresponding homogeneous equation,L(y)= 0, plus a particular solution of the nonhomogeneous equation.That is, ify=y hrepreents the general solution ofL(y)= 0, theny=yh+ y represents the general solution
ofL(y)= d, where y is any particular solution of the (solvable) nonhomogeneous linear equationL(y)= d.]
Example 11: Determine all solutions of the system
Write down the augmented matrix and perform the following sequence of operations:
-
8/13/2019 Vec-mat
22/27
Page 22of 2
Since only 2 nonzero rows remain in this final (echelon) matrix, there are only 2 constraints, and,consequently, 4 2 = 2 of the unknownsyandzsayare free variables. Lety= t1andz= t2.
Backsubstitution ofy= t1andz= t2into the second row (x 3y+ 4z= 1) gives
Finally, backsubstitutingx= 1 + 3 t1 42,y= t1,andz= t2into the first row (2 w 2x+y= 1)
determines w:
Therefore, every solution of this system has the form
where t1and t2are any real numbers. Another way to write the solution is as follows:
where t1, t2R.Example 12: Determine the general solution of
which is the homogeneous system corresponding to the nonhomoeneous one in Example 11 above.
-
8/13/2019 Vec-mat
23/27
Page 23of 2
Since the solution to the nonhomogeneous system in Example 11 is
Theorem C implies that the solution of the corresponding homogeneous systemis (where t1, t2R), which is obtained from (*) by simply discarding theparticular soluttion, x = (1/2,1,0,0), of the nonhomogeneous system.
Example 13: Prove Theorem A: Regardless of its size or the number of unknowns its equations contain, a
linear system will have either no solutions, exactly one solution, or infinitely many solutions.
Proof. Let the given linear system be written in matrix formAx= b. The theorem really comes down to tthiifAx= bhas more than one solution, then it actually has infinitely many. To establish this, let x1and x2be
two distinct solutions ofAx= b. It will now be shown that for any real value of t, the vector x1+ t(x1x2)
also a solution ofAx= b; because tcan take on infinitely many different values, the desired conclusion will
follow. SinceAx1= bandAx2,
Therefore, x1+ t(x1x2) is indeed a solution ofAx= b, and the theorem is proved.
Vectors and matrices in MATLAB
The purpose of this section is to demonstrate how to create and transform vectors and matrices inMATLAB.
This command creates a row vector
a = [1 2 3]
a =1 2 3Column vectors are inputted in a similar way, however, semicolons must separate the components
of a vector
b = [1;2;3]
b =
12
3The quote operator ' is used to create the conjugate transpose of a vector (matrix) while the dotquote
operator .' creates the transpose vector (matrix). To illustrate this let us form a complexvector a + i*b' and next apply these operations to the resulting vector to obtain
(a+i*b')'
ans =1.0000 - 1.0000i
2.0000 - 2.0000i
-
8/13/2019 Vec-mat
24/27
Page 24of 2
3.0000 - 3.0000i
while4
(a+i*b').'
ans =
1.0000 + 1.0000i2.0000 + 2.0000i
3.0000 + 3.0000iCommand length returns the number of components of a vector
length(a)
ans =3The dot operator.plays a specific role in MATLAB. It is used for the componentwise applicationof the operator that follows the dot operator
a.*a
ans =1 4 9
The same result is obtained by applying thepower operator ^ to the vector a
a.^2ans =1 4 9Componentwise division of vectors a and b can be accomplished by using the backslash operator\ together with the dot operator .
a.\b'
ans =1 1 1
For the purpose of the next example let us change vector a to the column vector
a = a'
a =1
23The dot product and the outer product of vectors a and b are calculated as follows
dotprod = a'*b
5dotprod =
14
outprod = a*b'
outprod =
1 2 32 4 63 6 9
The cross product of two three-dimensional vectors is calculated using command cross. Let thevector abe the same as above and let
b = [-2 1 2];
Note that the semicolon after a command avoids display of the result. The cross product of a andb is
cp = cross(a,b)
cp =
1 -8 5The cross product vector cp is perpendicular to both a and b
[cp*a cp*b']
-
8/13/2019 Vec-mat
25/27
Page 25of 2
ans =
0 0We will now deal with operations on matrices. Addition, subtraction, and scalar multiplication aredefined in the same way as for the vectors.This creates a 3-by-3 matrix
A = [1 2 3;4 5 6;7 8 10]
A =
1 2 34 5 67 8 10
Note that thesemicolon operator ; separates the rows. To extract a submatrix B consisting ofrows 1 and 3 and columns 1 and 2 of the matrix A do the following
B = A([1 3], [1 2])
B =1 2
7 8To interchange rows 1 and 3 of A use the vector of row indices together with the colon operator
C = A([3 2 1],:)
6
C =7 8 104 5 61 2 3
The colon operator : stands for all columns or all rows. For the matrix A from the last examplethe following command
A(:)
ans =
1472
583610creates a vector version of the matrix A. We will use this operator on several occasions.
To delete a row (column) use the empty vector operator [ ]
A(:, 2) = []
A =
1 34 67 10
Second column of the matrix A is now deleted. To insert a row (column) we use the technique forcreating matrices and vectors
A = [A(:,1) [2 5 8]' A(:,2)]
A =1 2 34 5 67 8 10
Matrix A is now restored to its original form.Using MATLAB commands one can easily extract those entries of a matrix that satisfy an impsedcondition. Suppose that one wants to extract all entries of that are greater than one. First, we
-
8/13/2019 Vec-mat
26/27
Page 26of 2
define a new matrix A
A = [-1 2 3;0 5 1]
A =-1 2 30 5 1
7Command A > 1 creates a matrix of zeros and ones
A > 1ans =0 1 1
0 1 0with ones on these positions where the entries of A satisfy the imposed condition and zeroseverywhere else. This illustrates logical addressing in MATLAB. To extract those entries of thematrix A that are greater than one we execute the following command
A(A > 1)
ans =25
3
The dot operator . works for matrices too. Let nowA = [1 2 3; 3 2 1] ;
The following command
A.*A
ans =1 4 9
9 4 1computes the entry-by-entry product of A with A. However, the following command
A*A
??? Error using ==> *
Inner matrix dimensions must agree.
generates an error message.
Function diag will be used on several occasions. This creates a diagonal matrix with the diagonalentries stored in the vector d
d = [1 2 3];
D = diag(d)
D =1 0 0
0 2 00 0 38
To extract the main diagonal of the matrix D we use function diag again to obtain
d = diag(D)
d =
12
3What is the result of executing of the following command?
diag(diag(d));
In some problems that arise in linear algebra one needs to calculate a linear combination ofseveral matrices of the same dimension. In order to obtain the desired combination both the
coefficients and the matrices must be stored in cells. In MATLAB a cell is inputted using curlybraces{ }. This
c = {1,-2,3}
-
8/13/2019 Vec-mat
27/27
c =
[1] [-2] [3]is an example of the cell. Function lincomb will be used later on in this tutorial.
function M = lincomb(v,A)
% Linear combination M of several matrices of the same size.
% Coefficients v = {v1,v2,,vm} of the linear combination and the
% matrices A = {A1,A2,...,Am} must be inputted as cells.
m = length(v);[k, l] = size(A{1});
M = zeros(k, l);
for i = 1:m
M = M + v{i}*A{i};
end