Prof. Vladimir A. Dobrushkin
This tutorial contains many matlab scripts.
You, as the user, are free to use all codes for your needs, and have the right to distribute this tutorial and refer to this tutorial as long as this tutorial is accredited appropriately. Any comments and/or contributions for this tutorial are welcome; you can send your remarks to
Methods involving difference quotient approximations for derivatives can be used for solving certain second-order boundary value problems. Consider the Dirichlet boundary value problem for the linear differential equation
There is a special scheme, called progonka or forward elimination and back substitution (FEBS) to solve algebraic equations with tridiagonal matrices. This scheme, which is widely used in numerical simulations, was first discovered by a prominent Soviet mathematician Israel Moiseevich Gel'fand (1913--2009) in his student work. He personally never claimed his authority for the discovery because he thought it was just easy (from his point of view) application of Gauss elimination. In engineering, the FEBS method is sometimes accosiated with Llewellyn H. Thomas from Bell laboratories who used it in 1946.
To solve the linear system of equations \( {\bf A} \,{\bf x} = {\bf b} , \) with tridiagonal matrix A, use the following matlab code:
function x=trisys(A,D,C,b)
% Input: A is the subdiagonal of the coefficient matrix
% D is the main diagonal of the coefficient matrix
% C is the superdiagonal of the coefficient matrix
% b is the constant vector of the linear system
% Output: x is the solution vector
n=length(b);
for k=2:n
mult=A(k-1)/D(k-1);
D(k)=D(k)-mult*C(k-1);
b(k)=b(k)-mult*b(k-1);
end
x(n)=b(n)/D(n);
for k=n-1:-1:1
x(k)=(b(k)-C(k)*X(k+1))/D(k);
end
Now we are ready to solve numerically teh boundary value problem
Remark: The uniform mesh is \( a= t_1 < t_2 < \cdots < t_{m+1} =b \) and the solution points are \( \left\{ (t_j , x_j ) \right\}_{j=1}^{m+1} .\)
function F=finddiff(p,q,r,a,b,alpha,beta,m)
% Input: p, q, r are the coefficient functions
% input as strings: 'p', 'q', 'r'
% a and b are the left and right end points
% alpha=x(a) and beta=x(b)
% m is the number of steps
% Output: F=[t',x'] where t' is the 1xm vector of abscissas
% and x' is the 1 x m vector of ordinates
% initialize vectors and h
t=zeros(1,m+1);
x=zeros(1,m-1);
va=zeros(1,m-2);
vb=zeros(1,m-1);
vc=zeros(1,m-2);
vd=zeros(1,m-1);
h=(b-a)/m;
% calculate the constant vector b in Ax=b
vt==a+h:h:a+h*(m-1);
vb=-h^2*feval(r,vt);
vb(1)=vb(1)+(1+h/2*feval(p,vt(1)))*alpha;
vb(m-1)=vb(m-1)+(1-h/2*feval(p,vt(m-1)))*alpha;
% calculate the main diagonal of A in A*x = b
vd=2+h^2*feval(q,vt);
% calculate the superdiagonal of A in A*x = b
vta=vt(1,2:m-1);
va=-1-h/2*feval(p,vta);
% calculate the subdiagonal of A in A*x = b
vtc=vt(1,1:m-2);
vc=-1+h/2*feval(p,vtc);
% solve A*x = b using trisys
x=trisys(va,vd,vc,vb);
t=[a,vt,b];
x=[alpha,x,beta];
F=[t',x'];