你好追赶法公式就是这样,只是三角分解更简单了罢了,下面代码供参考:
function x = chase(a, b, c, d)
if(numel(a)+1~=numel(b)||numel(b)~=numel(c)+1||numel(b)~=numel(d))
error('Not valid input, please check length of a,b,c,and d!')
end
a = a(:); b = b(:); c = c(:); d = d(:);
if(abs(b(1))-abs(c(1))<=0 || abs(b(end))-abs(a(end))<=0 || abs(a(end))<=0 || abs(c(1))<=0)
error('Input not satisfy the Tri condition');
elseif(numel(b)>=3 && any(abs(b(2:end-1))-abs(a(1:end-1))-abs(c(2:end))<0))
error('Input not satisfy the Tri condition');
end
p = zeros(size(b));
q = zeros(size(a));
n = numel(b);
p(1) = b(1);
for i = 1:1:n-1
q(i) = c(i)/p(i);
p(i+1) = b(i+1) - a(i)*q(i);
end
y = zeros(n,1);
y(1) = d(1)/p(1);
for i = 2:1:n
y(i) = (d(i) - a(i-1)*y(i-1))/p(i);
end
x = zeros(n,1);
x(n) = y(n);
for j = n-1:-1:1
x(j) = y(j) - q(j)*x(j+1);
end
end