Tuesday, August 6, 2019

Bary: The Barycentric Interpolation in MatLab


Purpose
  • The library "Bary" provides MatLab functions for the barycentric interpolation.

Click Here to Download the Codes


Specifications
  • Name:Bary
  • Author: Feng Chen
  • Version: 1.0
  • Language: MATLAB

Simple Example
  • Equation: \begin{equation} \begin{aligned} &c_1(x)u''(x)+ c_2(x)u'(x)+c_3(x)u(x) = f(x), \quad \Omega = (a,b),\\ &u \text{ satisifies the general boundary condition}. \end{aligned} \end{equation}
  • Parameters: \begin{equation} c_1(x)=-4x^2, \quad c_2(x) = 3x, \quad c_3(x)=2. \end{equation}
  • Exact solution and input functions: \begin{equation} u(x) = \sin x , \end{equation} then $f(x)$ is calculated accordingly.

Quick Start
  • Compiling and running:
    matlab test_bvp
    
  • Output:
     
    error =
    
       1.1180e-13
    
  • CPU: Intel(R) Core(TM) i5-4590S CPU @ 3.00GHz
  • OS: Ubuntu 18.04.
  • Release: MATLAB R2019a.

References
  • Tee, T. & Trefethen, L. A Rational Spectral Collocation Method with Adaptively Transformed Chebyshev Grid Points, SIAM Journal on Scientific Computing, Volume 28, Number 5, 1798-1811, (2006).

Core Subroutines
    
    
    function [P L U A] = bc_bvp_matrix(c1, c2, c3, a1, a2, b1, b2, D1, D2)
    
    n = length(c1);
    A = diag(c1)*D2 + diag(c2)*D1 + diag(c3);
    A(1,:) = a1*[1 zeros(1,n-1)] + b1*D1(1,:);
    A(n,:) = a2*[zeros(1,n-1) 1] + b2*D1(n,:);
    [L,U,P] = lu(A); 
    
    
    
    

No comments:

Post a Comment