Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [x] = RisolviTriangSup(U, y)
- % Risolve il sistema triangolare superiore Ux = y
- n = length(y);
- x(n) = y(n) / U(n, n);
- for k = n-1 : -1 : 1
- x(k) = (y(k) - U(k, k+1:n)*x(k+1:n)') / U(k, k);
- end
- end
- function [x] = Gauss(A, b)
- % Metodo di eliminazione di Gauss
- n = length(b);
- for k = 1 : n-1
- for i = k+1 : n
- m(i) = A(i,k) / A(k,k);
- for j = k+1 : n
- A(i,j) = A(i,j) - m(i)*A(k,j);
- end
- b(i) = b(i) - m(i)*b(k);
- end
- end
- x = RisolviTriangSup(triu(A), b);
- end
- A = [ -2.3 4 -1.5 -1;
- 4 -9.2 0.9 5;
- -4 5 -5 5.2;
- -8 8 -13.4 20];
- b = [1 -3 3 -2]';
- x = Gauss(A, b);
- x_true = A\b;
- norm(b - A*x') / norm(b)
- norm(x_true - x) / norm(x_true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement