function [X,Y,L,U]=chase(A,B) % 追赶法求解三对角方程组 % NUMERICAL METHODS: Matlab Programs % (c) 2007 by Xie Liling % Complementary Software to accompany the textbook: % Information and Computing Science: A Laboratory Course % 追 L=eye(size(A)); U=zeros(size(A)); U(1,1)=A(1,1); L(2,1)=A(2,1)/A(1,1); n=length(A(:,1)); for i=1:n-1 U(i,i+1)=A(i,i+1); end for i=2:n L(i,i-1)=A(i,i-1)/U(i-1,i-1); U(i,i)=A(i,i)-L(i,i-1)*A(i-1,i); end Y=zeros(size(B)); Y(1)=B(1); for i=2:n Y(i)=B(i)-L(i,i-1)*Y(i-1); end % 赶 X=zeros(size(B)); X(n)=Y(n)/U(n,n); for i=n-1:-1:1 X(i)=(Y(i)-U(i,i+1)*X(i+1))/U(i,i); end