Saturday, October 13, 2012

COBY: Standard 1-D Chebyshev collocation method


Purpose
  • The package "Coby" provides the common Chebyshe collocation method for solving the 1-D elliptic equation with the general boundary condition.

Specifications
  • Name: Coby.
  • Author: Feng Chen.
  • Finishing date: 10/13/2012.
  • Languages: MATLAB.

Simple Example
  • Equation: \begin{equation} \begin{aligned} & \alpha u - u'' = f, \quad x \in (-1,1), \\ & a_{\pm} u(\pm 1)+b_{\pm} u'(\pm 1)=c_{\pm}. \end{aligned} \end{equation}
  • Parameters: \begin{equation} \alpha = 3, \quad a_{\pm} =1, \quad b_{\pm} = 0. \end{equation}
  • Exact solution and input functions: \begin{equation} u(x) = \sin(\pi x), \end{equation} then $f(x)$ and $c_{\pm}$ are calculated accordingly.

Quick Start
  • Compiling and running:
    matlab Coby_Driver_Dirichlet
    
  • Output:
    
    
  • CPU: Intel(R) Xeon(R) CPU X5550 @2.67GHz.
  • OS: CentOS release 6.4 (Final).
  • Release: MATLAB R2012a.

References

Code Highlights
    
    % initialize the first-order collocation matrix
    D = cheb(N); 
    
    % second-order collocation matrix
    D2 = D*D;
    
    % construct the linear system
    A = alp*diag(ones(N+1,1))-D2;
    
    % modify the first and last row for boundary conditions
    A(1,:) = bp*D(1,:)+ap*[1,zeros(1,N)];
    A(N+1,:) = bm*D(N+1,:)+am*[zeros(1,N), 1];
    
    % modify right hand side for boundary conditions
    b = [cp;f(2:N);cm];
    
    % solve for the solution
    u = A\b;
    
    

No comments:

Post a Comment