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

📄 gausselimpivot.m

📁 A very simple Gaussian elimination code in matlab
💻 M
字号:
function [x] = gaussElimPivot(A,b, verbose)% File gaussElim.m%   This subroutine will perform Gaussian elmination%   on the matrix that you pass to it.%   i.e., given A and b it can be used to find x,%        Ax = b%%   To run this file you will need to specify several%   things:%   A - matrix for the left hand side.%   b - vector for the right hand side%%   The routine will return the vector x.%   ex: [x] = gaussElim(A,b)%     this will perform Gaussian elminiation to find x.%% N = max(size(A)); % Perform Gaussian Eliminationif verbose != 0 A bend  for j=2:N,	 maxVal = A(j-1, j-1);	 index = j-1;	 for k=j-1:N,	   checking = abs(A(k, j-1));	   if checking > maxVal	     maxVal = abs(A(k, j-1));     	     index  = k;	   end	 end	 if index != j-1	   A([index,j-1],:) = A([j-1,index],:);	   b([index,j-1],:) = b([j-1,index],:);	   if verbose != 0	     printf("***** Swapping %d with %d ******\n", index, j-1);	     A	     b	   end	 else	   if verbose != 0	     printf("***** No Swap ******\n");	   end	 end       for i=j:N,	 	 m = myRound(myRound(A(i,j-1))/myRound(A(j-1,j-1)));	 for k=1:N,	   A(i,k) = myRound(myRound(A(i,k)) - myRound(myRound(A(j-1,k))*myRound(m)));	 end	 b(i) = myRound(myRound(b(i)) - myRound(m)*myRound(b(j-1)));	   if verbose != 0	     printf("****** Eliminating %d, %d ******\n", i, j-1);	     A	     b	   end       end  end% Perform back substitution x = zeros(N,1); x(N) = myRound(myRound(b(N))/myRound(A(N,N)));  for j=N-1:-1:1,   x(j) = myRound(myRound((myRound(b(j))-myRound(A(j,j+1:N)*x(j+1:N))))/myRound(A(j,j))); end % A = [.6667 .2857 .2000; .3333 .1429 -.5000; .2000 -.4286 .4000]% b = [2.867 .8333 -2.400]'% A = [2 3 1; 4 1 4; 3 4 6]% b = [-4 9 0]' 

⌨️ 快捷键说明

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