Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

 Open In Colab

Consider an ODE y′=−yy(0)=1 y^\prime = -y \quad y(0) = 1, which has an analytical answer y=e−ty = e^{-t}.

We wish to approximate this function numerically between [0,1][0,1] with a line defined by the boundary points, f(0)=a=1f(0) = a = 1 and f(1)=bf(1) = b,

f(x)=[1−x]+xbf(x) = [1-x] + x b

How do we find bb?

Option 1: Direct substitution

Following the Finite Difference method, we can subsitute f(1)f(1) into the ODE and solve for b:

f′(1)=f(1)b−1=−bb=1/2\begin{align} f'(1) &= f(1) \\ b-1 &= -b \\ b &= 1/2 \end{align}

and the approximate solution is f=1−x2f = 1 -\frac{x}{2}

<Figure size 640x480 with 1 Axes>

Option 2: Least square minimization of the residual

Let’s integrate the squared residual of f(x) plugged into the ODE, y′+yy^\prime + y

R=f′(x)+f(x)=[b−1]+1−x+xb=b+x[b−1]R2=b2+2bx[b−1]+[x[b−1]]2F=∫01R2 dx=13[7b2−5b+1]\begin{align} R &= f^\prime(x) +f(x) \\ &= [b-1] + 1-x + x b \\ &= b+x[b-1] \\ R^2 &= b^2 + 2 b x[b - 1] + [x[b - 1]]^2 \\ F = \int_0^1 R^2 \ dx &= \frac{1}{3} [7 b^2 - 5 b + 1] \\ \end{align}

Note that in the end the integral of the residual, FF is a parabolic function of the parameter bb. The minimum is found at: ∂F∂b(b)=0\frac{\partial F}{\partial b}(b) = 0, for b=514b = \frac{5}{14}. The approximate solution is f(x)=1−914xf(x) = 1-\frac{9}{14}x.

<Figure size 1400x500 with 2 Axes>

We see that option 2 does a better job of approximating the function over the full domain since it focusses on the integral of the residual.

You may have noticed that we did something funny here: we integrated R2R^2 and then took its derivative with respect to bb in order to find the minimum of the integral! I.e.:

∂F∂b=0=∂∂b∫01R2 dx=∫012R∂R∂b dx=∫01Rv dx\begin{align} \frac{\partial F}{\partial b} = 0 &= \frac{\partial }{\partial b} \int_0^1 R^2 \ dx \\ &= \int_0^1 2R \frac{\partial R}{\partial b} \ dx \\ &= \int_0^1 R v \ dx \end{align}

where the residual has now been weighted by the function vv. This is called the Method of Weighted Residual [MWR]. Let’s try a different function and see what happens.

Option 3: Integrate the MWR to find the parameters

Integrate the weighted residual function directly with a convenient choice of vv.

lets take v=xv = x (to be motivated later) and integrate:

∂F∂b=0=∫01Rx dx=∫01[b+[b−1]x]x dx=∫01bx+[b−1]x2 dx=[16x2[3b+2[b−1]x]]01=b−25\begin{align} \frac{\partial F}{\partial b} =0 &= \int_0^1 R x \ dx \\ &= \int_0^1 \big[b+[b-1]x\big]x \ dx \\ &= \int_0^1 b x+[b-1]x^2 \ dx \\ &= \bigg[ \frac{1}{6} x^2\big[3b+2[b-1]x\big]\bigg]_0^1 \\ &= b-\frac{2}{5} \\ \end{align}

which is very close to our previous solution b=514b = \frac{5}{14} but with a simpler integration. BUT, we are still let with analytically integrating! If only there were a way to express integrals as the sum of the integrand evaluated at certain points...

Option 4: Express the MWR integral as the sum of the integrand evaluated at certain points.

Integrate the weighted residual function directly with a convenient choice of vv as the sum of the integrand evaluated at certain points:

Recall Gaussian Quadrature allows us to evaluate an integral by summing the integrand at the Gauss Points. The Gauss Points for the domain [−1,1][-1,1] are ±13\pm\frac{1}{\sqrt{3}}, scaled to this integral domain become,

x[0,1]]=0.5(x[−1,1]+1)=12[1±13]≈[0.21132487,0.78867513]\begin{align} x_{[0,1]]} &= 0.5 (x_{[-1,1]} + 1) \\ &= \frac{1}{2} \bigg[1 \pm\frac{1}{\sqrt{3}} \bigg] \\ &\approx [0.21132487, 0.78867513] \end{align}

and

0=∫01Rx dx=Rx(x=.21132487)+Rx(x=.78867513)=−0.0446582+0.255983b−0.622008+1.41068bb=25\begin{align} 0 &= \int_0^1 R x \ dx \\ &= Rx (x=.21132487) + Rx(x = .78867513) \\ &= -0.0446582 + 0.255983 b -0.622008 + 1.41068 b \\ b &= \frac{2}{5} \end{align}

Recap of the approach

Let’s recap what we’ve done:

  1. parameterized a function as a weighted sum of simpler functions (a linear basis)

  2. found a (simple) integral expression that minimizes the error in the approxiation (Minimized Weighted Residual)

  3. performed the integration exactly using only function evaluations into a linear system (Gaussian quadrature)

  4. Solved the linear system (I told you everything boiled down to linear systems!)

Practical solution of linear systems requires sparsity! Let’s formalize our proceedure and see how we can ensure sparsity.