p1_mrg_matrix1

2894 days ago by LAC2011

a=matrix(2,2,(1,5,-1,2));a #initialize a 2x2 matrix 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr}
1 & 5 \\
-1 & 2
\end{array}\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr}
1 & 5 \\
-1 & 2
\end{array}\right)
b=matrix(2,2,(-2,1,1,1));b #initialize a 2x2 matrix 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr}
-2 & 1 \\
1 & 1
\end{array}\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr}
-2 & 1 \\
1 & 1
\end{array}\right)
c=a+b;c #find matrix sum 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr}
-1 & 6 \\
0 & 3
\end{array}\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr}
-1 & 6 \\
0 & 3
\end{array}\right)
d=a-b;d #find matrix difference 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr}
3 & 4 \\
-2 & 1
\end{array}\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr}
3 & 4 \\
-2 & 1
\end{array}\right)
e=a*b;e #find matrix product 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr}
3 & 6 \\
4 & 1
\end{array}\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr}
3 & 6 \\
4 & 1
\end{array}\right)
f=b*a;f #find matrix product 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr}
-3 & -8 \\
0 & 7
\end{array}\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr}
-3 & -8 \\
0 & 7
\end{array}\right)
g=matrix(2,3,(1,2,3,4,5,6));g #initialize a 2x3 matrix 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rrr}
1 & 2 & 3 \\
4 & 5 & 6
\end{array}\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rrr}
1 & 2 & 3 \\
4 & 5 & 6
\end{array}\right)
h=matrix(3,2,(0,-1,2,-3,4,-5));h #initialize a 2x3 matrix 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr}
0 & -1 \\
2 & -3 \\
4 & -5
\end{array}\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr}
0 & -1 \\
2 & -3 \\
4 & -5
\end{array}\right)
i=g*h;i #find matrix product 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr}
16 & -22 \\
34 & -49
\end{array}\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr}
16 & -22 \\
34 & -49
\end{array}\right)
j=a**2;j #find matrix powers 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr}
-4 & 15 \\
-3 & -1
\end{array}\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr}
-4 & 15 \\
-3 & -1
\end{array}\right)
k=b**3;k #find matrix powers 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr}
-11 & 4 \\
4 & 1
\end{array}\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr}
-11 & 4 \\
4 & 1
\end{array}\right)
#find matrix inverse l=a**(-1) print l print a print det(a) 
       
[ 2/7 -5/7]
[ 1/7  1/7]
[ 1  5]
[-1  2]
7
[ 2/7 -5/7]
[ 1/7  1/7]
[ 1  5]
[-1  2]
7
#find matrix inverse m=b**(-1) print m.n() print b print b.det() 
       
[-0.333333333333333  0.333333333333333]
[ 0.333333333333333  0.666666666666667]
[-2  1]
[ 1  1]
-3
[-0.333333333333333  0.333333333333333]
[ 0.333333333333333  0.666666666666667]
[-2  1]
[ 1  1]
-3
#solve simultaneous equations x+5y=1, -2x+y=2 n=matrix(2,2,(1,5,-2,1)) o=matrix(2,1,(1,2)) print n print o print det(n) print n**(-1) print n**(-1)*o 
       
[ 1  5]
[-2  1]
[1]
[2]
11
[ 1/11 -5/11]
[ 2/11  1/11]
[-9/11]
[ 4/11]
[ 1  5]
[-2  1]
[1]
[2]
11
[ 1/11 -5/11]
[ 2/11  1/11]
[-9/11]
[ 4/11]
#solve simultaneous equations x+5y=1, -2x+y=2 n.solve_right(o) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{r}
-\frac{9}{11} \\
\frac{4}{11}
\end{array}\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{r}
-\frac{9}{11} \\
\frac{4}{11}
\end{array}\right)
#solve simultaneous equations x+5y=1, -2x+y=2 n\o 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{r}
-\frac{9}{11} \\
\frac{4}{11}
\end{array}\right)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{r}
-\frac{9}{11} \\
\frac{4}{11}
\end{array}\right)