標籤

C (1) maple (2) Matlab (11) paper (1) python (14)

2011年9月6日 星期二

GE

%
%----GE.m----
disp('-----------------------------------')
disp('to slove A x = b ,given A and b ...')
disp('-----------------------------------')
n=input('the dimension of A = ')
A=input('A = ')%A=rand(n)
b=input('b = ')%b=rand(n,1)
A(:,n+1)=b
for j=1:n
       if A(j,j)==0
           temp=0;
             for p=1:n-j
               if A(j+p,j)~=0
                    Q=A(j,:);
                    A(j,:)=A(j+p,:);
                    A(j+p,:)=Q;
                    temp=1;
                    break
               end
             end
             if temp == 0
                 disp('bye')
                 return
             end
       end
          for i=1:n
              if i~=j
                 A(i,:)=((-1)*(A(i,j)/A(j,j))*A(j,:)+A(i,:))/A(i,i);
                 A
              end
          end
       end

沒有留言:

張貼留言