2026-04-01
\[ \begin{split}\begin{array}{c} y_1 = a x_1 + b x_2 \\ y_2 = c x_1 + d x_2 \end{array}\end{split} \]
\[ \begin{split}\begin{array}{c} y_1 = a_{11} x_1 + a_{12} x_2 + \cdots + a_{1k} x_k \\ \vdots \\ y_n = a_{n1} x_1 + a_{n2} x_2 + \cdots + a_{nk} x_k \end{array}\end{split} \]
This Lecture
We will show how to use Julia to solve these problems numerically.
\[ x = \left(\begin{matrix} x_1\\\vdots\\ x_n\end{matrix}\right) \]
[].= (dot means “do for each element”)ArgumentError: indexed assignment with a single value to possibly many locations is not supported; perhaps use broadcasting `.=` instead? Stacktrace: [1] setindex_shape_check(::Tuple{Int64, Int64}, ::Int64) @ Base ./indices.jl:276 [2] _unsafe_setindex!(::IndexLinear, A::Vector{Float64}, x::Tuple{Int64, Int64}, I::UnitRange{Int64}) @ Base ./multidimensional.jl:1017 [3] _setindex! @ ./multidimensional.jl:1008 [inlined] [4] setindex!(A::Vector{Float64}, v::Tuple{Int64, Int64}, I::UnitRange{Int64}) @ Base ./abstractarray.jl:1443 [5] top-level scope @ ~/University of Oregon Dropbox/David Evans/University of Oregon/Courses/Spring 2026/EC 410/Lectures and Website/Julia/Linear Algebra/Linear Algebra Lecture.qmd:138
\[ \begin{split}x + y = \left[ \begin{array}{c} x_1 \\ x_2 \\ \vdots \\ x_n \end{array} \right] + \left[ \begin{array}{c} y_1 \\ y_2 \\ \vdots \\ y_n \end{array} \right] := \left[ \begin{array}{c} x_1 + y_1 \\ x_2 + y_2 \\ \vdots \\ x_n + y_n \end{array} \right]\end{split} \]
\[ \begin{split}\gamma x := \left[ \begin{array}{c} \gamma x_1 \\ \gamma x_2 \\ \vdots \\ \gamma x_n \end{array} \right]\end{split} \]
.* notation[1.0, 1.0, 1.0][2, 4, 6]
3-element Vector{Float64}:
2.0
4.0
6.0
The Dot Operator
In Julia, prefixing an operator with . applies it element-wise. This works with any function or operator!
\[ x' y := \sum_{i=1}^n x_i y_i \]
\[ \| x \| := \sqrt{x' x} := \left( \sum_{i=1}^n x_i^2 \right)^{1/2} \]
12.0
12.0
1.7320508075688772
1.7320508075688772
\[ y = \beta_1 a_1 + \beta_2 a_2 + \ldots + \beta_k a_k \text{ for some scalars $\beta_1,\ldots,\beta_k$} \]
\[ e_1 = \left[\begin{matrix}1\\0\\\vdots\\0\end{matrix}\right],\quad e_2 = \left[\begin{matrix}0\\1\\\vdots\\0\end{matrix}\right],\quad\ldots,\quad e_n = \left[\begin{matrix}0\\0\\\vdots\\1\end{matrix}\right] \]
\[ x = x_1 e_1 + x_2 e_2 + \ldots + x_n e_n \]
Key Insight
Adding more vectors doesn’t always increase the span — the new vector must point in a “genuinely new direction.”
\[ y = \beta_1 a_1 + \ldots + \beta_k a_k = \gamma_1 a_1 + \ldots + \gamma_k a_k \]
\[ (\beta_1 - \gamma_1) a_1 + \cdots + (\beta_k - \gamma_k) a_k = 0 \]
\[ \begin{split}A = \left[ \begin{array}{cccc} a_{11} & a_{12} & \cdots & a_{1k} \\ a_{21} & a_{22} & \cdots & a_{2k} \\ \vdots & \vdots & \vdots \\ a_{n1} & a_{n2} & \cdots & a_{nk} \end{array} \right]\end{split} \]
\[ A = \left[\begin{matrix}a_1 & a_2 & \cdots & a_k\end{matrix}\right] \quad\text{where}\quad a_i = \left[\begin{matrix} a_{1i}\\ a_{2i} \\\vdots \\ a_{ni}\end{matrix}\right] \]
\[ \begin{split}A = \left[ \begin{array}{ccc} a_{11} & a_{12} & \cdots & a_{1k} \\ \vdots & \vdots & \vdots \\ a_{n1} & a_{n2} & \cdots & a_{nk} \end{array} \right] \quad A' = \left[ \begin{array}{ccc} a_{11} & a_{21} & \cdots & a_{n1} \\ \vdots & \vdots & \vdots \\ a_{1k} & a_{2k} & \cdots & a_{nk} \end{array} \right]\end{split} \]
\[ I = \left[\begin{matrix}e_1 & e_2 & \cdots & e_n\end{matrix}\right] \]
\[ \gamma A := \left[ \begin{array}{ccc} \gamma a_{11} & \cdots & \gamma a_{1k} \\ \vdots & \vdots & \vdots \\ \gamma a_{n1} & \cdots & \gamma a_{nk} \end{array} \right] \]
\[ Ax = \left[ \begin{array}{c} a_{11} x_1 + \cdots + a_{1k} x_k \\ \vdots \\ a_{n1} x_1 + \cdots + a_{nk} x_k \end{array} \right] \]
\[ Ax = x_1 a_1 + x_2 a_2 + \ldots + x_k a_k \]
.*. notationCan these arrays be broadcast together?
A (4d array): 8 x 1 x 6 x 1
B (3d array): 7 x 1 x 5
Result (4d array): 8 x 7 x 6 x 5
What about these?
A (2d array): 2 x 1
B (3d array): 8 x 4 x 3
No — the second dimensions do not match.
\[ \begin{split}\begin{array}{c} y_1 = a_{11} x_1 + a_{12} x_2 + \cdots + a_{1k} x_k \\ \vdots \\ y_n = a_{n1} x_1 + a_{n2} x_2 + \cdots + a_{nk} x_k \end{array}\end{split} \]
\[ g(\alpha w + \beta z) = \alpha g(w) + \beta g(z) \]
\[ I = A^{-1}A = A A^{-1} \]
\[ A^{-1} y = A^{-1} A x = x \]
Key Result
\(x = A^{-1}y\) is the solution to \(y = Ax\) when \(A\) is square and invertible.
A\y (backslash) to solve directlyBest Practice
Prefer A\y over inv(A)*y — it is more numerically stable and efficient.
pinvFit a line \(y = mx + c\) through noisy data:
\[ A(x + \hat{x}) = Ax + A\hat{x} = Ax + 0 = y \]
Caution
Under-determined systems have infinitely many solutions. Methods like pinv return the solution with smallest norm \(\|x\|\).
\[ Av = \lambda v \]
Nice facts about the eigenvalues of a square matrix \(A\):
Eigen{Float64, Float64, Matrix{Float64}, Vector{Float64}}
values:
2-element Vector{Float64}:
-1.0
3.0
vectors:
2×2 Matrix{Float64}:
-0.707107 0.707107
0.707107 0.707107
Reading the Output
The columns of evecs are the eigenvectors corresponding to the eigenvalues in evals.
\[ x = Ax + d \]
\[ x - Ax = d \quad \Longrightarrow \quad (I - A)x = d \quad \Longrightarrow \quad x = (I - A)^{-1} d \]
\[ (I - A)^{-1} = I + A + A^2 + A^3 + \cdots \]
| Term | Meaning |
|---|---|
| \(I\) | Direct output (the good itself) |
| \(A\) | First-round inputs |
| \(A^2\) | Inputs to produce the inputs |
| \(A^k\) | \(k\)-th round of indirect effects |
\((I - A)^{-1}\) exists with non-negative entries if the spectral radius of \(A\) is less than 1
Productive Economy
The spectral radius condition means each industry uses less than one unit of total inputs per unit of output. If it fails, the economy consumes more than it produces.
Three sectors: Agriculture, Manufacturing, Services
3×3 Matrix{Float64}:
0.1 0.2 0.05
0.15 0.1 0.1
0.05 0.15 0.1
Spectral radius: 0.3376
Economy is productive: true
Suppose final demand is \(d = (100, 200, 150)'\):
Final demand: [100.0, 200.0, 150.0]
Gross output: [185.27, 277.91, 223.28]
Intermediate: [85.27, 77.91, 73.28]
What if manufacturing demand increases by 50 units?
Change in gross output: [13.7, 59.02, 10.6]
Multiplier Effect
A demand shock in one sector ripples through the entire economy via input-output linkages.
Concepts
Julia Tools
LinearAlgebra packagedot, norm, detinv(A), A\ypinv(A) for least-squareseigen(A) for eigenvalues.*, .+ for broadcastingEC 410 | University of Oregon