PHOT 411: Numerical Methods for Photonics

LECTURE 02

Michaël Barbier, Spring semester (2024-2025)

Outlook

  • Introduction to solving systems of linear equations numerically
  • Introduction to finding roots to solve equations in one variable

Solving systems of linear equations

Linear equations

A system of linear equations with

  • Unknown variables \(x_i\)
  • Constant coefficients \(a_{ij}\)
  • Constants \(b_i\)

\[ \left\{ \begin{aligned} a_{11}x_1 + a_{12}\,x_1 + \dots + a_{1n}\,x_n & = b_1\\ a_{21}x_1 + a_{22}\,x_2 + \dots + a_{2n}\,x_n & = b_2\\ \vdots\qquad & \\ a_{m1}x_1 + a_{m2}x_2 + \dots + a_{mn}x_n & = b_m\\ \end{aligned} \right. \]

Solving small systems

A system of linear equations with

  • Unknown variables \(x_i\)
  • Constant coefficients \(a_{ij}\)
  • Constants \(b_i\)

\[ \left\{ \begin{aligned} a_{11}\, x_1 + a_{12}\,x_2 & = b_1\\ a_{21}x_1 + a_{22}\,x_2 & = b_2\\ \end{aligned} \right. \]

Matrix equations

  • Systems of linear equations in matrix-form

\[ \begin{pmatrix} a_{11} & a_{12} & \dots & a_{1n}\\ a_{21} & a_{22} & \dots & a_{2n}\\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \dots & a_{mn}\\ \end{pmatrix} \begin{pmatrix} x_1\\ x_2\\ \vdots\\ x_m\\ \end{pmatrix} = \begin{pmatrix} b_1\\ b_2\\ \vdots\\ b_m\\ \end{pmatrix} \]

Which can be written more compact:

\[ [A] \, [x] = [b] \qquad \textrm{or} \qquad A \, x = b \qquad \textrm{or} \qquad A \, \vec{x} = \vec{b} \]

Approximating functions

Discretizing functions

  • simplest: finite number of \(x_i\) and \(y_i = f(x_i)\) (with \(i = 1, \dots , N\))
  • Points \(x_i\) can be regularly spaced
  • Accuracy depends on:
    • how smooth the real function is
    • how close the points are taken But more points \(\longrightarrow\) more data, slower

Discretizing functions

  • The actual function is smooth

Discretizing functions

  • The actual function is smooth
  • Approximation: orange piece-wise constant curve

Discretizing functions

  • The actual function is smooth
  • Approximation: orange piece-wise constant curve
  • Very sparse approximation: green curve not a good representation

Discretizing functions

  • How many points should be taken?
  • More points take up more memory and require more calculations
  • Choose interval length and stepsize according to function/problem

Finding roots

  • Finding roots equivalent to solving an equation in one variable
    \[ \sin(x) - \frac{x^2}{100} = \frac{x^3}{2000} \qquad\Rightarrow\qquad \sin(x) - \frac{x^2}{100} - \frac{x^3}{2000} = 0 \]

Finding roots

  • Find where \(f(x) = \sin(x) - x^2/100 - x^3/2000\) is zero
  • Ability to find roots of any function \(f(x)\) \(\quad\Longrightarrow\quad\) Solve every equation
  • Other examples of equations:
    \[ \begin{aligned} a x^2 + b x + c &= 0\\ x^7 + 5 x^2 - x &= 1\\ x \, \arcsin(x) &= \pi/4 x^2\\ \cos(\pi x^2) &= \frac{1}{|x| + 1}\\ \end{aligned} \]