octave: Orthogonal Collocation

 
 23.2 Orthogonal Collocation
 ===========================
 
  -- : [R, AMAT, BMAT, Q] = colloc (N, "left", "right")
      Compute derivative and integral weight matrices for orthogonal
      collocation.
 
      Reference: J. Villadsen, 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 ]