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

📄 lusub.m

📁 matlab算法集 matlab算法集
💻 M
字号:
function [x,Delta] = lusub (L,U,P,b)
%----------------------------------------------------------------
% Usage:      [x,Delta] = lusub (L,U,P,b)
%
% Descripton: Solve a factored linear algebraic system LUx = Pb
%
% Inputs:     L = n by n matrix containing lower-triangular factor.
%             U = n by n matrix containing upper-triangular factor
%                 with U(k,k) = 1.
%             P = n by n row permutation matrix.
%             b = n by 1 right-hand side vector.
%
% Outputs:    x     = n by 1 solution to Ax = b where PA = LU.
%             Delta = determinant of LU 
%
% Notes:      The function lusub is used with the function
%             lufac to efficiently solve the system Ax = b
%             multiple times using different right-hand side
%             vectors b. The matrices (L,U,P) are created
%             by a single call to lufac. 
%----------------------------------------------------------------

% Check for singular LU

   chkvec (b,4,'lusub');
   n = size (L,1);
   x = zeros (n,1);
   Delta = L(1,1);
   for i = 2 : n
      Delta = L(i,i)*Delta;
   end
   if (abs(Delta) < eps)
      Delta = 0; 
      return;
   end

% Sort the right-hand side vector 
 
   d = P*b;

% Perform forward substitution to find y 
 
   y = zeros (n,1);
   for k = 1 : n
      y(k) = d(k);
      for i = 1 : k-1
         y(k) = y(k) - L(k,i)*y(i);
      end
      y(k) = y(k)/L(k,k);
   end

% Perform back substitution to find x 
 
   for k = n : -1 : 1
      x(k) = y(k);
      for i = k+1 : n
         x(k) = x(k) - U(k,i)*x(i);
      end
   end
%----------------------------------------------------------------

⌨️ 快捷键说明

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