You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lectures/linear_equations.md
+21-46Lines changed: 21 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,8 +41,6 @@ from matplotlib import cm
41
41
from mpl_toolkits.mplot3d import Axes3D
42
42
```
43
43
44
-
+++
45
-
46
44
## A Two Good Example
47
45
48
46
We discuss a simple two good example and solve it by
@@ -128,8 +126,6 @@ Traditionally, vectors are represented visually as arrows from the origin to the
128
126
129
127
The following figure represents three vectors in this manner.
130
128
131
-
+++
132
-
133
129
```{code-cell} ipython3
134
130
fig, ax = plt.subplots(figsize=(10, 8))
135
131
# Set the axes through the origin
@@ -139,7 +135,7 @@ for spine in ['right', 'top']:
139
135
ax.spines[spine].set_color('none')
140
136
141
137
ax.set(xlim=(-5, 5), ylim=(-5, 5))
142
-
ax.grid()
138
+
143
139
vecs = ((2, 4), (-3, 3), (-4, -3.5))
144
140
for v in vecs:
145
141
ax.annotate('', xy=v, xytext=(0, 0),
@@ -378,8 +374,6 @@ np.sqrt(np.sum(x**2)) # Norm of x, take one
378
374
np.linalg.norm(x) # Norm of x, take two
379
375
```
380
376
381
-
+++
382
-
383
377
## Matrix Operations
384
378
385
379
```{index} single: Matrix; Operations
@@ -590,8 +584,6 @@ NumPy arrays are also used as matrices, and have fast, efficient functions and m
590
584
591
585
You can create them manually from tuples of tuples (or lists of lists) as follows
592
586
593
-
+++
594
-
595
587
```{code-cell} ipython3
596
588
A = ((1, 2),
597
589
(3, 4))
@@ -630,8 +622,6 @@ B = np.ones((3, 3)) # 3 x 3 matrix of ones
630
622
A + B
631
623
```
632
624
633
-
+++
634
-
635
625
To multiply matrices we use the `@` symbol.
636
626
637
627
@@ -855,8 +845,6 @@ It can be verified manually that this system has no possible solution.
855
845
856
846
To illustrate why this situation arises let's plot the two lines.
857
847
858
-
+++
859
-
860
848
```{code-cell} ipython3
861
849
fig, ax = plt.subplots(figsize=(5, 4))
862
850
x = np.linspace(-10,10)
@@ -866,7 +854,7 @@ plt.legend()
866
854
plt.show()
867
855
```
868
856
869
-
+++
857
+
+++ {"tags": []}
870
858
871
859
Clearly, these are parallel lines and hence we will never find a point $x \in \mathbb{R}^2$
872
860
such that these lines intersect.
@@ -894,12 +882,11 @@ We can rewrite this system in matrix form as
894
882
895
883
It can be noted that the $2^{nd}$ row of matrix $A = (2, 6)$ is just a scalar multiple of the $1^{st}$ row of matrix $A = (1, 3)$.
896
884
897
-
Matrix $A$ in this case is called **linearly dependent.**
885
+
The rows of matrix $A$ in this case is called **linearly dependent.**
898
886
899
-
Linear dependence arises when one row of a matrix can be expressed as a [linear combination](https://en.wikipedia.org/wiki/Linear_combination)
900
-
of the other rows.
887
+
A collection of vectors $A$ is called linearly dependent whenever a vector $v \in A$ can be expressed as a [linear combination](https://en.wikipedia.org/wiki/Linear_combination) of all the other vectors in $A$.
901
888
902
-
A matrix that is **not** linearly dependent is called **linearly independent**.
889
+
A collection of vectors that is **not** linearly dependent is called **linearly independent**.
903
890
904
891
We will keep our discussion of linear dependence and independence limited but a more detailed and generalized
905
892
explanation can be found [here](https://python.quantecon.org/linear_algebra.html#linear-independence).
@@ -919,7 +906,7 @@ Any vector $v = (x,y)$ such that $x = 2y - 4$ will solve the above system.
919
906
920
907
Since we can find infinite such vectors this system has infinitely many solutions.
921
908
922
-
Check whether the matrix
909
+
Check whether the rows
923
910
924
911
```{math}
925
912
:label: many_solns
@@ -930,7 +917,7 @@ Check whether the matrix
930
917
\end{bmatrix}
931
918
```
932
919
933
-
is linearly dependent or independent.
920
+
are linearly dependent or independent.
934
921
935
922
We can now impose conditions on $A$ in {eq}`la_se2` that rule out these problems.
936
923
@@ -954,9 +941,9 @@ $$
954
941
If the determinant of $A$ is not zero, then we say that $A$ is
955
942
*nonsingular*.
956
943
957
-
A square matrix $A$ is nonsingular if and only if $A$ is linearly independent.
944
+
A square matrix $A$ is nonsingular if and only if the rows and columns of $A$ are linearly independent.
958
945
959
-
You can check yourself that the linearly dependent matrices in {eq}`no_soln` and {eq}`many_solns` are singular matrices
946
+
You can check yourself that the in {eq}`no_soln` and {eq}`many_solns` with linearly dependent rows are singular matrices
960
947
as well.
961
948
962
949
This gives us a useful one-number summary of whether or not a square matrix can be
@@ -994,8 +981,6 @@ We can now solve for equilibrium prices with NumPy's `linalg` submodule.
994
981
995
982
All of these routines are Python front ends to time-tested and highly optimized FORTRAN code.
996
983
997
-
+++
998
-
999
984
```{code-cell} ipython3
1000
985
C = ((10, 5), #matrix C
1001
986
(5, 10))
@@ -1054,29 +1039,17 @@ q = C @ p # equilibrium quantities
1054
1039
q
1055
1040
```
1056
1041
1057
-
+++
1058
-
1059
1042
Observe how we can solve for $x = A^{-1} y$ by either via `inv(A) @ y`, or using `solve(A, y)`.
1060
1043
1061
1044
The latter method uses a different algorithm that is numerically more stable and hence should be the default option.
1062
1045
1063
-
NOTE Add more examples. Perhaps Tom has suggestions.
1064
-
1065
-
NOTE Perhaps discuss LU decompositions in a very simple way?
1066
-
1067
-
1068
-
1069
-
1070
1046
1071
1047
### Further Reading
1072
1048
1073
1049
The documentation of the `numpy.linalg` submodule can be found [here](https://numpy.org/devdocs/reference/routines.linalg.html).
1074
1050
1075
1051
More advanced topics in linear algebra can be found [here](https://python.quantecon.org/linear_algebra.html#id5).
0 commit comments