0% found this document useful (0 votes)
11 views

MN Algoritmi Matlab

This document contains code for several matrix factorization and linear equation solving algorithms including Cholesky decomposition, Crout decomposition, Gaussian elimination with partial and complete pivoting, and functions for solving linear systems using the LU and Cholesky factorizations. The algorithms are implemented in MATLAB/Octave code.

Uploaded by

Stefan Ion
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

MN Algoritmi Matlab

This document contains code for several matrix factorization and linear equation solving algorithms including Cholesky decomposition, Crout decomposition, Gaussian elimination with partial and complete pivoting, and functions for solving linear systems using the LU and Cholesky factorizations. The algorithms are implemented in MATLAB/Octave code.

Uploaded by

Stefan Ion
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

function[l]= Cholesky(a) for j=k+1:n disp(x);

[n,n] = size(a); if abs(A(i,j)) > max


for i=1:n max = abs(A(i,j));
for j=1:i-1 p = i;
s=0; q=j; function[ x ]=S_INF_TR(L,b)
for k=1:j-1 n=length(b);
s=s+l(i,k)*l(j,k); for i=1:n
end s=b(i);
l(i,j)=(a(i,j)-s)/l(j,j); end if i>1
end for k=1:(i-1)
q=0; %interschimba linia p cu linia k s=s-L(i,k)*x(k);
for k=1:i-1 %aux = A(k,:); A(k,:) = end
q=q+l(i,k)^2; A(p,:); A(p,:) = aux; end
end aux = A(:,k); A(:,k) = A(:,q); A(:,q) = x(i)=s/L(i,i);
l(i,i)=sqrt(a(i,i)-q); aux; end
aux = b(k); b(k) = b(p); b(p) = x=x';
aux; end
function [L U] = Crout(A) for i=k+1:n
[n,n] = size(A); t = A(i,k) / A(k,k); % t = element
L = zeros(n); for j=k:n function [ x ] = S_SUP_TR( U,b )
U = eye(n); A(i,j) = A(i,j) - t * A(k,j); %UNTITLED Summary of this function goes
L(1 : n, 1) = A(1 : n, 1); end here
for k = 1 : n b(i) = b(i) - t*b(k); % Detailed explanation goes here
for i = k : n end n=length(b);
% -------------------------------- for i=n:-1:1
s = 0; function [A,b] = GPP(A,b) %eliminarea s=b(i);
for m = 1 : k-1 gausiana cu pivotare partiala if(i<n)
s = s + L(i, m) * U(m, k); % la pasul p aduce pe pozitia (p,p) elementul for k=(i+1):n
end de abs(el) maxim s=s-U(i,k)*x(k);
% -------------------------------- [n,n] = size(A); end
% echivalent pentru calculul sumei b=b(:); end
% s = L(i, 1 : k-1) * U(1 : k-1, k); for k=1:n-1 x(i)=s/U(i,i);
L(i, k) = A(i, k) - s; max = 0;
end p=k; end
for j = k+1 : n for i=k+1:n x=x'
% -------------------------------- if abs(A(i,k)) > max
s = 0; max = abs(A(i,k)); function [ x ] = SLGPP( A,b )
for m = 1 : k-1 p = i; %UNTITLED4 Summary of this function goes
s = s + L(k, end here
m) * U(m, j); end % Detailed explanation goes here
end %interschimba linia p cu linia k %[n,n]=size(A);
% --------------------------------- aux = A(k,:); A(k,:) = [U,c]=GPP(A,b);
% echivalent pentru calculul sumei A(p,:); A(p,:) = aux; x=S_SUP_TR(U,c);
% s = L(k, 1 : k-1) * U(1 : k-1, j); aux = b(k); b(k) = b(p); b(p) =
U(k, j) = (A(k, j) - s) / L(k, k); aux; function UINV(u)
end for i=k+1:n [n,n]=size(u);
t = A(i,k) / A(k,k); % t = element for j=n:-1:1
function [A, b] = elimGauss(A, b) for j=k:n x(j,j)=1/u(j,j);
[n, n] = size(A); A(i,j) = A(i,j) - t * A(k,j); if j==1
for k = 1 : n-1 end end
for i = k + 1 : n b(i) = b(i) - t*b(k); for i=j-1:-1:1
t = A(i, k) / A(k, k); end s=0;
%A(i,k:n) = A(i, k:n) - t* A(k, k:n); for k=i+1:j
for j=k:n s=s+u(i,k)*x(k,j);
A(i,j) = A(i, j) - t* A(k, j); function LINV(l) end
end [n,n]=size(l); x(i,j)=-s/u(i,i);
b(i) = b(i) - t * b(k); for j=1:n end
end x(j,j)=1/l(j,j); end
if j==n disp(x);
function [A,b] = GPC(A,b) %eliminarea end end
gausiana cu pivotare partiala for i=j+1:n
% la pasul p aduce pe pozitia (p,p) elementul s=0;
de abs(el) maxim for k=j:i-1
[n,n] = size(A); s=s+l(i,k)*x(k,j);
b=b(:); end
for k=1:n-1 x(i,j)=-s/l(i,i);
max = 0; end
p=k; end
for i=k+1:n

You might also like