︠f7b2427e-ca38-497f-9efb-cd213576649ci︠
%hide
%md
## Inverse of Matrix
︡f6114cfa-626d-468e-8045-03d7a73b2cc2︡{"hide":"input"}︡{"md":"## Inverse of Matrix "}︡{"done":true}
︠6bbfa6fa-03b9-4b0d-899c-13d113e9a808i︠
%hide
%latex
\begin{flushleft}
So far we have been working on given $X_n, A$, find $X_{n+1}$\\
Can we do it reversely?
\end{flushleft}
︡f4de291e-594b-40ae-96a1-15849d178794︡{"hide":"input"}︡{"file":{"filename":"/tmp/tmp9Cqley.png","show":true,"text":null,"uuid":"b2f0df9e-cbd5-4803-a4ff-fc7386595621"},"once":false}︡{"done":true}
︠558d1a15-e373-4edd-8307-7a67252836fai︠
%hide
%md
︡bae6ab4a-f14d-4132-bcaa-85a56e9e0d98︡{"hide":"input"}︡{"md":"
\n"}︡{"done":true}
︠f8e54d48-b501-4143-8ea9-6f324dade2c3i︠
e288fc6a-68ac-41a3-bced-38f3084f04f2
e288fc6a-68ac-41a3-bced-38f3084f04f2
%hide
%latex
\begin{flushleft}
For a matrix A, and vectors X and B\\
AX = B\\
If I give you B and A, can you find X for me?\\
Yes!!!!\\
X = $A^{-1}B$
\end{flushleft}
︡b0d3d98c-b56b-47c9-8080-5595a6fc2d09︡{"hide":"input"}︡{"file":{"filename":"/tmp/tmpxzyMSl.png","show":true,"text":null,"uuid":"71fe0d87-31c4-4050-81b7-543bce734019"},"once":false}︡{"done":true}
︠5e01f61c-0665-4edd-a96c-a0cfd865575bi︠
%hide
%md
︡1c2f8ad6-068a-4418-b029-18488bb51d8a︡{"hide":"input"}︡{"md":"
\n"}︡{"done":true}
︠34d6a88d-d95b-4aeb-b9c5-d5b735e00584i︠
%hide
%latex
\begin{flushleft}
$AX = B \implies X = A^{-1}B \ne BA^{-1}$ (order matters)\\
e.g.
A=$\begin{bmatrix}1&2\\3&4\end{bmatrix}, B = \begin{bmatrix}4\\2\end{bmatrix}, X = \begin{bmatrix}x_1\\x_2\end{bmatrix}$\\
$AX = \begin{bmatrix}x_1+2x_2\\3x_1+4x_2\end{bmatrix} = \begin{bmatrix}4\\2\end{bmatrix}\implies x_1=-6,x_2 = 4$\\ (Wait, this solution has to deal with B's value, can we find a expression for all B's?)
\end{flushleft}
︡5411b913-3f3d-4bec-8715-af3cb71b25c0︡{"hide":"input"}︡{"file":{"filename":"/tmp/tmpvU5xsD.png","show":true,"text":null,"uuid":"45d4962f-9087-456a-b698-3bbb09fda51f"},"once":false}︡{"done":true}
︠cf5b560c-a339-4338-bed4-0bc9f6771691i︠
%hide
%md
︡4a3be138-495e-4c1d-89e6-a7881b285d2e︡{"hide":"input"}︡{"md":"
\n\n"}︡{"done":true}
︠d05b70b1-622d-4c74-bf0e-729b420c4908i︠
%hide
%latex
\begin{flushleft}
Question: Can we express it with a matrix? ($A^{-1}$) (So we can solve it without knowing B)\\
A=$\begin{bmatrix}1&2\\3&4\end{bmatrix}, B = \begin{bmatrix}b_1\\b_2\end{bmatrix}, X = \begin{bmatrix}x_1\\x_2\end{bmatrix}$\\
$AX = \begin{bmatrix}x_1+2x_2\\3x_1+4x_2\end{bmatrix} = \begin{bmatrix}b_1\\b_2\end{bmatrix}\implies x_1=b_2-2b_1,x_2 = \frac{3}{2}b_1-\frac{1}{2}b_2$\\
$\implies \begin{bmatrix}-2&1\\1.5&-0.5\end{bmatrix}B = X$
\end{flushleft}
︡0b98a45c-dc51-4d29-907a-a421717ac997︡{"hide":"input"}︡{"file":{"filename":"/tmp/tmpdjj838.png","show":true,"text":null,"uuid":"3704f21f-63d2-463e-86b2-762403d5ecff"},"once":false}︡{"done":true}
︠84479bac-063d-4566-935e-ecbacc1a934cs︠
A = matrix(RDF,[[1,2],[3,4]])
B = vector([4,2])
X = A.inverse()*B
X
A*X
A.inverse()
︡99608123-3e80-4074-ab69-726db0c5a42d︡{"stdout":"(-5.999999999999998, 4.999999999999999)\n"}︡{"stdout":"(4.0, 2.0000000000000036)\n"}︡{"stdout":"[-1.9999999999999996 0.9999999999999998]\n[ 1.4999999999999998 -0.4999999999999999]\n"}︡{"done":true}
︠8d991002-6463-4d78-a402-846004e16280s︠
@interact
def FindX(target = vector([4,2]),x1=(-7,7,1),x2=(-7,7,1)):
B = vector([4,2])
v1 = vector([1,3])
v2 = vector([2,4])
vres = v1*x1+v2*x2;
fig = plot(v1*x1,color='red',linestyle='--')+plot(v2*x2,color='blue',linestyle='--')+plot(vres,color='green')+point(B,size=30,color='black')
show(fig)
︡2b68779f-339c-4d87-b989-b96d5d4f44c7︡{"interact":{"controls":[{"control_type":"input-box","default":"(4, 2)","label":"target","nrows":1,"readonly":false,"submit_button":null,"type":null,"var":"target","width":null},{"animate":true,"control_type":"slider","default":0,"display_value":true,"label":"x1","vals":["-7","-6","-5","-4","-3","-2","-1","0","1","2","3","4","5","6","7"],"var":"x1","width":null},{"animate":true,"control_type":"slider","default":0,"display_value":true,"label":"x2","vals":["-7","-6","-5","-4","-3","-2","-1","0","1","2","3","4","5","6","7"],"var":"x2","width":null}],"flicker":false,"id":"3c36db3e-c70d-49fc-a89c-8743e4e4951a","layout":[[["target",12,null]],[["x1",12,null]],[["x2",12,null]],[["",12,null]]],"style":"None"}}︡{"done":true}
︠5d9fbaac-082c-4f39-b92c-a8f093688272i︠
%hide
%latex
\begin{flushleft}
$A^{-1} = \frac{1}{A}$\\
$A\times A^{-1} = I = \begin{bmatrix}1&0\\0&1\end{bmatrix}$, like 1\\
(p.s. Inverse does not always exist)\\
For scalar, if a =0, $\frac{1}{a}$ does not exist!!\\
So when does $A^{-1}$ do not exist??
\end{flushleft}
︡1de0e93b-3d90-4b5c-aa24-37beb2d5812f︡{"hide":"input"}︡{"file":{"filename":"/tmp/tmp4MZo1P.png","show":true,"text":null,"uuid":"72fff4a7-eaea-4879-8481-9cf62504b467"},"once":false}︡{"done":true}
︠9dd2b099-70d7-45b9-83c6-2596f12cd89fi︠
%hide
%md
## Change of Basis
︡709f57d9-75e1-48f7-ad1c-abb0814fbcab︡{"hide":"input"}︡{"md":"## Change of Basis "}︡{"done":true}
︠821c9a57-843b-4e1d-800a-7ce99befa78di︠
%hide
%latex
\begin{flushleft}
Any vector we see now is actually a combination of basis vectors!!!\\
$\begin{bmatrix}x_1\\x_2\end{bmatrix} = x_1\begin{bmatrix}1\\0\end{bmatrix}+x_2\begin{bmatrix}0\\1\end{bmatrix}$\\
For a matrix $T = \begin{bmatrix}t_1&t_2\end{bmatrix}$\\
$T\begin{bmatrix}x_1\\x_2\end{bmatrix} = x_1t_1+x_2t_2$\\
T maps the original vector $X$, from the world $t_1,t_2$ to another world of $\begin{bmatrix}1\\0\end{bmatrix},\begin{bmatrix}0\\1\end{bmatrix}$ \\
$\implies T^{-1}$ maps from world $\begin{bmatrix}1\\0\end{bmatrix},\begin{bmatrix}0\\1\end{bmatrix}$ back to $t_1,t_2$
\end{flushleft}
︡4c64667c-efef-44c7-ad13-c678b7866db7︡{"hide":"input"}︡{"file":{"filename":"/tmp/tmpZ4Pmsg.png","show":true,"text":null,"uuid":"18501940-0f00-456a-941c-853034aaed57"},"once":false}︡{"done":true}
︠58cf251b-2bbc-46d4-bb28-899730e5350bo︠
︡2d02702e-b61d-4aeb-b89d-52d5a6395934︡
︠665e2f1e-0f37-46a8-806a-223288a92760i︠
%hide
%md
## Sometimes $T^{-1}$ Does not exist
## If $T =[t_1 t_1]$ => multiple vectors in T's world maps to the same vector in world $\begin{bmatrix}1\\0\end{bmatrix}$ and $\begin{bmatrix}0\\1\end{bmatrix}$
## Cannot map back!!!
### $\implies T^{-1}$ exists if and only if all $t_1, t_2, t_3......$ cannot be form by any other basis except itself.
#### Impossible to find $t_1 = at_2 + bt_3$ for any a and b. (3 dimensional case)
︡568b6a23-5238-4888-8157-496978673126︡{"hide":"input"}︡{"md":"## Sometimes $T^{-1}$ Does not exist\n## If $T =[t_1 t_1]$ => multiple vectors in T's world maps to the same vector in world $\\begin{bmatrix}1\\\\0\\end{bmatrix}$ and $\\begin{bmatrix}0\\\\1\\end{bmatrix}$\n## Cannot map back!!!\n\n### $\\implies T^{-1}$ exists if and only if all $t_1, t_2, t_3......$ cannot be form by any other basis except itself.\n#### Impossible to find $t_1 = at_2 + bt_3$ for any a and b. (3 dimensional case)"}︡{"done":true}
︠c8fd3c15-57df-49db-bc69-8564b45badeei,i︠
%hide
%md
## Diagonalization
︡a9aaacd2-ca63-471c-863c-7e48d2dba405︡{"hide":"input"}︡{"md":"## Diagonalization"}︡{"done":true}
︠06436a6d-7a35-433a-a437-1865ab5c674ei︠
%hide
%latex
\begin{flushleft}
A is a 2x2 matrix, has eigen values $\lambda_1,\lambda_2$, eigen vectors $V_1=\begin{bmatrix}x_1\\y_1\end{bmatrix},V_2=\begin{bmatrix}x_2\\y_2\end{bmatrix}$\\
What is $A\begin{bmatrix}V_1&V_2\end{bmatrix}$?\\
Question:\\ $A\begin{bmatrix}x_1&x_2\\y_1&y_2\end{bmatrix}= $\\
(a) $\begin{bmatrix}\lambda_1&\lambda_2\\\lambda_1&\lambda_2\end{bmatrix}\begin{bmatrix}x_1\\y_1\end{bmatrix}$\\
(b) $\begin{bmatrix}\lambda_2&\lambda_1\\\lambda_1&\lambda_2\end{bmatrix}\begin{bmatrix}x_1&x_2\\y_1&y_2\end{bmatrix}$\\
(c) $\begin{bmatrix}\lambda_1&0\\0&\lambda_2\end{bmatrix}\begin{bmatrix}x_1&x_2\\y_1&y_2\end{bmatrix}$\\
(d) $\begin{bmatrix}x_1&x_2\\y_1&y_2\end{bmatrix}\begin{bmatrix}\lambda_1&0\\0&\lambda_2\end{bmatrix}$\\
\end{flushleft}
︡1eeadb29-6b31-40e9-8b83-1967cb1fd591︡{"hide":"input"}︡{"file":{"filename":"/tmp/tmp_GlQ0b.png","show":true,"text":null,"uuid":"db82d763-05d8-4a90-bae8-9de21124fe51"},"once":false}︡{"done":true}
︠6d506b29-9906-499e-8987-857197b7051ai︠
%hide
%latex
\begin{flushleft}
$T = \begin{bmatrix}x_1&x_2\\y_1&y_2\end{bmatrix}$\\
$AT = T\begin{bmatrix}\lambda_1&0\\0&\lambda_2\end{bmatrix}$\\
$ T^{-1}AT=\begin{bmatrix}\lambda_1&0\\0&\lambda_2\end{bmatrix}$
\end{flushleft}
︡2d316e5d-b543-444f-b91c-0be1d85ef21a︡︡{"file":{"filename":"/tmp/tmpWrsuCh.png","show":true,"text":null,"uuid":"98e27cc7-8cc2-4a50-878c-406f99eb561a"},"once":false}︡{"done":true}
︠293e8543-d513-480f-853c-d635ebe47afbi︠
%hide
%md
## Longterm Effect
︡051c955a-be5e-4541-a9aa-c554973fe7b8︡{"hide":"input"}︡{"md":"## Longterm Effect "}︡{"done":true}
︠cd8d0a1c-d6cf-4951-b2c6-a9b7e968f1bci︠
%hide
%latex
\begin{flushleft}
$X_{n+1} = AX_n$\\
$X_{n+2} = AX_{n+1} = A^2X_n$\\
$X_{n+3} = AX_{n+2} = A^3X_n$\\
$X_{n+2} = AX_{n+3} = A^4X_n$\\
$X_{n+2} = AX_{n+4} = A^5X_n$\\
$X_{n+2} = AX_{n+5} = A^6X_n$
\end{flushleft}
︡5c0fbd0b-de59-483b-afef-e72221f18202︡{"hide":"input"}︡{"file":{"filename":"/tmp/tmpJ5Js8H.png","show":true,"text":null,"uuid":"6577e1e4-6680-4afa-aa36-0c12668b9026"},"once":false}︡{"done":true}
︠efd711cf-59a3-4ec6-b02c-216ce5b716e6i︠
%hide
%md
## Can we find $A^6$?
$T^{-1}ATT^{-1}ATT^{-1}ATT^{-1}ATT^{-1}ATT^{-1}AT$
︡e280f4e3-504d-4157-86f5-cd2a71dabcea︡{"hide":"input"}︡{"md":"## Can we find $A^6$? \n$T^{-1}ATT^{-1}ATT^{-1}ATT^{-1}ATT^{-1}ATT^{-1}AT$\n
"}︡{"done":true}
︠7fc41ec3-0f25-4c9d-8976-fed860d0d4a0i︠
%hide
%md
## Can we find $A^6$?
$T^{-1}ATT^{-1}ATT^{-1}ATT^{-1}ATT^{-1}ATT^{-1}AT$ = $T^{-1}A^6T$
︡e3aea645-6879-47f4-b6e0-02c2b833a517︡{"hide":"input"}︡{"md":"## Can we find $A^6$? \n$T^{-1}ATT^{-1}ATT^{-1}ATT^{-1}ATT^{-1}ATT^{-1}AT$ = $T^{-1}A^6T$"}︡{"done":true}
︠a9bf9046-63d2-49bf-be10-9f82d7d2b978i︠
%hide
%latex
\begin{flushleft}
$T = \begin{bmatrix}x_1&x_2\\y_1&y_2\end{bmatrix}$\\
$AT = T\begin{bmatrix}\lambda_1&0\\0&\lambda_2\end{bmatrix}$\\
$ T^{-1}AT=\begin{bmatrix}\lambda_1&0\\0&\lambda_2\end{bmatrix}$\\
$ T^{-1}A^6T=\begin{bmatrix}\lambda_1^6&0\\0&\lambda_2^6\end{bmatrix}$\\
$ A^6=T\begin{bmatrix}\lambda_1^6&0\\0&\lambda_2^6\end{bmatrix}T^{-1}$
\end{flushleft}
︡5c820008-c9d7-40de-8a5b-b68899e26dd6︡{"hide":"input"}︡{"file":{"filename":"/tmp/tmpJwd_Na.png","show":true,"text":null,"uuid":"fda5afc0-8199-4220-adfc-5f6c50785214"},"once":false}︡{"done":true}
︠1f5e56f6-8762-44fb-886c-c35df54fb6f5s︠
T = matrix(RDF,[[1,1],[2,0.5]])
v1 = vector([2,3])
T.inverse()*v1
v2 = vector([-5,1.2])
v3 = vector([-4,-8])
T.inverse()*v2
T.inverse()*v3
︡6ec4dfda-01e0-43dc-8064-b8316158ad0b︡{"stdout":"(1.3333333333333335, 0.6666666666666665)\n"}︡{"stdout":"(2.4666666666666663, -7.466666666666666)\n"}︡{"stdout":"(-4.0, 0.0)\n"}︡{"done":true}
︠d0cd505e-0ae8-4ca1-b82c-d6a87cc9c6d9︠
@interact
def findR()