Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- A=[3,1,-1;-1,5,-1;2,4,8]
- b=[6;10;2]
- wynik=A\b
- [x,Ur] = f_gauss(A,b)
- function [x,Ur]=f_gauss(A,b)
- [n,m]=size(A);
- x = zeros(n,1);
- if (n~=m) error('Macierz A musi byc kwadratowa'); end
- Ur = [A,b];
- for k=1:(n-1)
- if A(k,k)==0
- error;
- end
- for jj=k+1:(n+1)
- for ii=k+1:n
- Ur(ii,jj)=Ur(ii,jj)-Ur(ii,k)*Ur(k,jj)/Ur(k,k);
- end
- end
- end
- %x=0;
- for ii=n:-1:1
- S=0;
- for jj=ii+1:n
- S=S+Ur(ii,jj)*x(jj);
- end
- x(ii)=(Ur(ii,n+1)-S)/Ur(ii,ii)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement