⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trisub.m

📁 matlab算法集 matlab算法集
💻 M
字号:
function [x,Delta] = trisub (Q,b)
%----------------------------------------------------------------------
% Usage:      [x,Delta] = trisub (Q,b)
%
% Descripton: Solve the factored tridiagonal linear algebraic system
%             Ax = b using forward and back substitution.
%
% Inputs:     Q = 3 by n matrix containing lower and upper-triangular
%                 factors of A.  Q is obtained by a previous call to
%                 function trifac. 
%             b = n by 1 right-hand side vector
%
% Outputs:    x     = n by 1 solution vector
%             Delta = the determinant of A.  If Delta ~= 0, then x is
%                     valid.
%----------------------------------------------------------------------

   chkvec (b,2,'trisub');
   ep = eps/100;
   Delta = 1;
   [m,n] = size(Q);
   for k = 1 : n
      Delta = Delta*Q(2,k);
      if abs(Delta) < ep
         Delta = 0;
         return
      end
   end
      
% Perform forward substitution to find y 
 
   y = zeros (n,1);
   y(1) = b(1)/Q(2,1);
   for k = 2 : n 
      y(k) = (b(k) - Q(3,k-1)*y(k-1))/Q(2,k);
   end
    
% Perform back substitution to find x 

   x = zeros (n,1);
   x(n) = y(n);
   for k = n-1 : -1 : 1 
      x(k) = y(k) - Q(1,k)*x(k+1);
   end
%----------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -