For Ax=b, How do I make LU decomposition (A=L*U) without using lu function. For example, A is nxn matrix and bis nx1 matrix.
23 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Thanachart Wongmark
le 5 Sep 2020
Réponse apportée : David Hill
le 5 Sep 2020
clc
clear
A=rand(5)
b=rand(5,1);
A(2:3,1)
n=length(A)
U=A;
for i=1:n
k=i+1
i
U(k:n,i)=U(k:n,i)-U(i,i)*(U(k:n,i)/U(i,i))
end
for k= 1:n
L(k+1:n,k)=A(k+1:n,k)/A(k,k)
end
This is what I have try so far, I am very new to MATLAB like 2 week and genuinely struggle here.
0 commentaires
Réponse acceptée
David Hill
le 5 Sep 2020
function [L,U] = mylu(A)
n = size(A,1);
for k = 1:n
if A(k,k)==0
warning('LU factorization fails');
L = []; U = []; return;
end
i = k+1:n;
A(i,k) = A(i,k)/A(k,k);
A(i,i) = A(i,i)-A(i,k)*A(k,i);
end
L = tril(A,-1)+eye(n); U = triu(A);
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Linear Algebra dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!