Econ 407: More on Matrices
>
with(linalg):
A:=linalg[matrix](3,3,[4,1,-5,-2,3,1,3,-1,4]);
Warning, new definition for norm
Warning, new definition for trace
>
IDM:=matrix([[1,0,0],[0,1,0],[0,0,1]]);
Definition: An identity matrix is a square matrix which has one on the main diagonal and 0 everywhere else, such as the matrix IDM shown above. Multiplying Matrix A by the identity matrix would return the A matrix as expected.
>
C:=evalm(A&*IDM);
We can expand a matrix by using the two commands agument or concat as shown below:
>
a := matrix([[1,2],[2,3]]);
>
b := matrix(2,3,[3,4,5,6,7,8]);
>
augment(a,b);
>
v := vector(2,[1,2]);
>
concat(v,b,v);
In the above examples we create a new matrix by joining a and b, or joing a vector, a matrix and a vector. This is a useful tool for solving equation sytems. See page 223 of the text and the following example.
Suppose you want to solve the following sytems of equations for x1 and x2:
2x1 + 12x2 = 40
8x1 + 4x2 =28
>
a:=matrix([[2,12],[8,4]]);
>
b:=matrix([[40],[28]]);
>
C:=augment(a,b);
By appropriate additions and subtractions for rows and cols, we can reduce the C matrix to:
>
Note that 2 is the solution for x1, and 3 is the solution for x2, and the first part is just an identity
matrix. We can also solve the system by multiplying the inverse of the a matrix by the b matrix. See the following example. 4x1+x2-5x3=8, -2x1+3x2+x3=12, 3x1-x2+4x3=5. Using matrix notation to show the A and the b matrix.
>
A:=matrix([[4,1,-5],[-2,3,1],[3,-1,4]]);
b:=vector([8,12,5]);
>
restart;
>
A:=matrix([[4,1,-5],[-2,3,1],[3,-1,4]]);
>
aa:=inverse(A);
>
>
b:=vector([8,12,5]);
>
with(linalg):
Warning, new definition for norm
Warning, new definition for trace
>
d1:=det(A);
d1 := 98
>
Ain:=inverse(A);
>
X:=evalm(Ain&*b);
We can also use the solve command to solve the system for x1, x2, and x3.
>
solve({4*x1+x2-5*x3=8, -2*x1+3*x2+x3=12, 3*x1-x2+4*x3=5},{x1,x2,x3});
Note that the solutions are identical.