Previous: Functions of One Variable, Up: Quadrature
Compute derivative and integral weight matrices for orthogonal collocation using the subroutines given in J. Villadsen and M. L. Michelsen, Solution of Differential Equation Models by Polynomial Approximation.
Here is an example of using colloc
to generate weight matrices
for solving the second order differential equation
u' - alpha * u” = 0 with the boundary conditions
u(0) = 0 and u(1) = 1.
First, we can generate the weight matrices for n points (including the endpoints of the interval), and incorporate the boundary conditions in the right hand side (for a specific value of alpha).
n = 7; alpha = 0.1; [r, a, b] = colloc (n-2, "left", "right"); at = a(2:n-1,2:n-1); bt = b(2:n-1,2:n-1); rhs = alpha * b(2:n-1,n) - a(2:n-1,n);
Then the solution at the roots r is
u = [ 0; (at - alpha * bt) \ rhs; 1] => [ 0.00; 0.004; 0.01 0.00; 0.12; 0.62; 1.00 ]