function y=nma_ForwardSub(L,w) %function y=nma_ForwardSub(L,w) % %Forward substitution that solves the lower triangular system %Ly=w for y % % %INPUT: % L: an nxn L, lower tirangular square matrix % w: vector of size n % %OUTPUT: % y: the solution to L*y=w % By Nasser M. Abbasi % HW 4, MATH 501, CSUF % % LU decomposition with threshold support. % Copyright (C) 2007 Nasser Abbasi % % This program is free software; you can redistribute it and/or % modify it under the terms of the GNU General Public License % as published by the Free Software Foundation; either version 2 % of the License, or (at your option) any later version. % % This program is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. % % You should have received a copy of the GNU General Public License % along with this program; if not, write to the Free Software % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA % 02110-1301, USA. %EXAMPLE RUN % >> [L,U,P]=nma_LU(A,0); % >> nma_ForwardSub(L,b) % % ans = % % 0.83849604493808 % 0.36727512318587 % 0.12405626870025 % -0.14539724685973 % 0.17813906538571 % -0.19809655526705 % % >> if nargin ~= 2 error 'Only two inputs are required' end if ~(isnumeric(L)&isnumeric(w)) error 'input must be numeric' end [nRow,nCol]=size(w); if nRow>1 & nCol>1 error 'w must be a vector not a matrix' end [nRow,nCol]=size(L); if nRow ~= nCol error 'Matrix L must be square' end if length(w) ~= nRow error 'w length does not match L matrix dimension' end y=zeros(nRow,1); y(1)=w(1)/L(1,1); w=w(:); for n=2:nRow y(n)=( w(n) - L(n,1:n-1)*y(1:n-1) ) / L(n,n); end end