[心得] 高斯-喬登消去法

看板MATLAB作者 (Bishop)時間13年前 (2012/06/06 18:59), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
最近剛好碰到這方面的作業,內容是用 while 和 for 寫的 不過沒有偵錯功能,還請大家批評指教 function a=GJ_elimi(b) % Gauss-Jordan elimination % b contains coefficients of a, b, ... and constant C for each column coeffi=b(:,1:end-1); L=length(coeffi); const=b(:,end); % upper matrix form S=1; while S<=L-1 for i=S+1:L k=coeffi(i,S)/coeffi(S,S); coeffi(i,:)=coeffi(i,:)-coeffi(S,:)*k; const(i)=const(i)-const(S)*k; end S=S+1; end % reduced row echelon form S=L; while S>=2 for i=S-1:-1:1 k=coeffi(i,S)/coeffi(S,S); coeffi(i,:)=coeffi(i,:)-coeffi(S,:)*k; const(i)=const(i)-const(S)*k; end S=S-1; end % make diagonal terms '1' N=diag(coeffi); coeffi=coeffi./repmat(N,1,L); const=const./N; a=[coeffi const]; -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.63.249 ※ 編輯: ht15trep 來自: 140.112.63.249 (06/06 19:00)
文章代碼(AID): #1FppWbgl (MATLAB)