We will be working with the elementary ODE
R(x) = y'' - 6x = 0 on [0,1] with y(0) = 0 and y(1) = 1.(See DeVries, First Course in Computational Physics.)
Approximate y(x) in the ODE with p(x) where
p(x) = a x2 + b x + c.Here the basis functions are the monomials Phi2(x) = x2, Phi1(x) = x1, and Phi0(x) = x0 = 1. The coefficients a, b, c are to be determined from the boundary conditions and the requirement that the equation is approximately solved. Impose the boundary condition and show that
R(x) = 2a - 6xSo we have only one free parameter left to play with. This residual parameterizes the error in our approximation. We want to make it as close to zero on the inverval [0,1] as we can.
This method picks a set of points on the interval and sets the residual to zero. That is, choose a set {xi} and require R(xi) = 0. Given the number of free parameters, how many points can we use in our case?
Choose the middle of the interval (x1 = 0.5). Show that you get a = 3/2. Plot the approximation and the exact solution side-by-side and discuss the difference.
Choose the domain [0,1] and set the average to zero. Determine a.
I = int(R2(x),x=0..1)Show that you also get a = 3/2. But please understand that there are no guarantees that the various methods will always agree.
We require that the inner product of the residual and a set of basis functions vanishes. The inner product of two functions is defined as the integral of the product over the interval. That is, we require
int( R(x)*Phii(x),x=0..1) = 0for some choice of values for i. Given the number of free parameters we have, how many such conditions can we impose?
Try Phi1(x) and show that you get a = 2.
I(y(x)) = int(1/2 (dy/dx)2 + 6 x y, x = 0..1)is to be minimized for all functions y(x) that satisfy the boundary conditions. It can be shown that the function that minimizes it satisfies the differential equation.
For optimizing our approximation, we plug in the approximation and find the parameters that minimize the variational integral.
Show that for our approximation,
I = a2/6 - a/2 + 5/2and find the value a that minimizes it. Then calculate the variational integral for the exact solution and show that it lowers the minimum value of I.
The example here is so simple, we were left with only one parameter to play with, and with each method we had only one linear constraint equation to solve. For more complex problems in any number of dimensions we would use typical finite element basis sets of compact support. Depending on how well we wanted to approximate the solution and the power of our computer, the number of parameters unconstrained by boundary conditions could be extremely large. The constraint equations would generate a large linear system in the parameters. But with a basis of compact support, the linear system would be sparse and easily solved with iterative methods.