it is a very essential matlab code.

源代码在线查看: gepivot.mht

软件大小: 82 K
上传用户: xufengping716
关键词: essential matlab code very
下载地址: 免注册下载 普通下载 VIP

相关代码

				From: 
				Subject: 
				Date: Tue, 12 May 2009 09:49:51 -0700
				MIME-Version: 1.0
				Content-Type: text/html;
					charset="Windows-1252"
				Content-Transfer-Encoding: 7bit
				Content-Location: http://www.mece.ualberta.ca/Courses/mec390/390code/gepivot.m
				X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3350
				
				
				
				
				
				% partial pivoting routine called by gauselim
				%
				% USAGE:   [A, err] = gepivot(A, k)
				%
				% where        A = augmented matrix
				%              k = current pivot row
				%            err = error code
				%                = 0 = no error
				%                = 1 = matrix is singular
				
				function [A, err] = gepivot(A, k)
				
				err = 0;
				[n, m] = size(A);
				
				piv = A(k,k);
				newpivot = k;
				
				for i = k+1:n            % check all rows below pivot
				   if abs(A(i,k)) > abs(piv) 
				       newpivot = i;
				       piv = A(i,k);
				   end
				end
				
				if piv == 0              % trouble - can't avoid 0 pivot
				   err = 1;
				elseif newpivot ~= k     % best pivot elsewhere, swap rows
				   for j = k:m
				     temp1 = A(k,j);
				     temp2 = A(newpivot,j);
				     A(k,j) = temp2;
				     A(newpivot,j) = temp1;
				   end
				end
				
				
				
							

相关资源