2026-11-13
\[ \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 — and why solving nonlinear systems comes down to solving a sequence of linear ones.
\[ 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:277 [2] _unsafe_setindex!(::IndexLinear, A::Vector{Float64}, x::Tuple{Int64, Int64}, I::UnitRange{Int64}) @ Base ./multidimensional.jl:1045 [3] _setindex! @ ./multidimensional.jl:1036 [inlined] [4] setindex!(A::Vector{Float64}, v::Tuple{Int64, Int64}, I::UnitRange{Int64}) @ Base ./abstractarray.jl:1464 [5] top-level scope @ ~/work/EC410-Source/EC410-Source/Linear Algebra/Linear Algebra Lecture.qmd:140
\[ \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\|\).
\[ 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 |
Productive Economy
When the column sums are below 1 the economy is productive: the Leontief inverse is a sum of non-negative matrices, so it is non-negative. If industries needed more than $1 of inputs per $1 of output, the economy would consume 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
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.
A \ y\[ f(x) = 0, \qquad f: \mathbb{R}^n \to \mathbb{R}^n \]
Big Idea
Replace \(f\) with a linear approximation, solve that linear system, and repeat. Linear algebra is the engine inside nonlinear solvers.
Two goods that are substitutes, with constant-elasticity demand and supply:
\[ D_1 = 100\, p_1^{-2} p_2^{0.5}, \quad S_1 = 20\, p_1^{1.5}, \qquad D_2 = 80\, p_2^{-1.5} p_1^{0.3}, \quad S_2 = 15\, p_2^{2} \]
2-element Vector{Float64}:
-21.213203435596427
-25.177977468155035
\[ f(x) \approx f(x_n) + J(x_n)\,(x - x_n) \]
\[ J(x_n)\, \Delta = -f(x_n), \qquad x_{n+1} = x_n + \Delta \]
Each Newton Step Is a Linear System
\(J(x_n)\Delta = -f(x_n)\) is \(Ax = y\) with \(A = J(x_n)\) and \(y = -f(x_n)\). In Julia: Δ = J(x) \ (-f(x))
Differentiate each market’s excess demand with respect to each price:
\[ J(p) = \begin{bmatrix} -200\, p_1^{-3} p_2^{0.5} - 30\, p_1^{0.5} & 50\, p_1^{-2} p_2^{-0.5} \\ 24\, p_1^{-0.7} p_2^{-1.5} & -120\, p_1^{0.3} p_2^{-2.5} - 30\, p_2 \end{bmatrix} \]
jacobian (generic function with 1 method)
2-element Vector{Float64}:
1.6919253416011006
1.6889430060896855
newton: Pseudocodenewton: Full Functionfunction newton(f, J, x₀; tol = 1e-10, maxiter = 50)
x = x₀
for n in 1:maxiter
Δ = J(x) \ (-f(x)) # linearize, then solve
x = x + Δ # take the step
println("iteration $n: ‖f(x)‖ = $(norm(f(x)))")
if norm(Δ) < tol # converged: steps are tiny
return x
end
end
println("Warning: no convergence after $maxiter iterations")
return x
endnewton (generic function with 1 method)
f and J are passed in as arguments — functions are values in Julia, so newton works for any systemiteration 1: ‖f(x)‖ = 1.3883008911248673
iteration 2: ‖f(x)‖ = 0.009203787568081082
iteration 3: ‖f(x)‖ = 4.049338246528834e-7
iteration 4: ‖f(x)‖ = 0.0
iteration 5: ‖f(x)‖ = 0.0
2-element Vector{Float64}:
1.7069573735223966
1.6889575066262879
Linear Systems Take One Step
If \(f(x) = Ax - y\) then \(J = A\) everywhere, and the first Newton step lands exactly on \(A^{-1}y\). Newton’s method generalizes A \ y.
solveEC410 provides solve(f, x0)2-element Vector{Float64}:
1.7069573735223966
1.6889575066262879
solve1D(f, a, b) (with a bracket) or solve1D(f, x0)[1.5174899135519797, 1.3027756377319946]
[-1.5174899135519797, 1.3027756377319946]
Always Check
Verify that \(f(x^*) \approx 0\), read any solver warnings, try several initial guesses, and make sure the answer makes economic sense (e.g. positive prices).
Concepts
Julia Tools
LinearAlgebra packagedot, norm, detinv(A), A\ypinv(A) for least-squaresJ \ (-f) for a Newton stepsolve(f, x0) from EC410.*, .+ for broadcastingEC 410 | University of Oregon