I have to follow a specific algorithm for this code but my L and U are coming out as single digits, not matrix and I am not sure why/ how to do that (algorithm is attached as picture)
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
function [L, U] = crout_LU( A ) %this function decomposes matrix A into a lower triangular matrix L and an %upper triangular matrix U, using Crout's method such that LU = A % A = matrix of coefficients % U = upper triangular matrix % L = lower triangular matrix
[r,c] = size(A); n = length(r); L = zeros(n); U = eye(n);
if r ~= c error('A is not a square matrix') elseif any(diag(A) == 0) warning('diagnol element of is 0') end
for k = 1:n L(k,1)=A(k,1); U(k,k)=1; for i = 2:n U(1,k)=A(1,k)/L(1,1); end
for i = k:n
sum_i = 0;
for m = 1: k - 1
sum_i = sum_i + L(i,m)*k(m,k);
end
L(i,k) = A(i,k) - sum_i;
end
for j = k+1:n
sum_j = 0;
for z = 1: k-1
sum_j = sum_j + L(k,z)*U(z,j);
end
U(k,j) = (A(k,j) - sum_j)/L(k,k);
end
end
end
0 Commenti
Risposte (1)
David Goodmanson
il 20 Ott 2016
Modificato: David Goodmanson
il 20 Ott 2016
Hi Melissa, you have
[r c] = size(A); n = length(r)
but r is just a scalar that tells you the number of rows in A, so length(r) = 1 and n is set to 1 which of course is not correct.
As a simple alternative to the debugger, it's easy to take semicolons off of the ends of lines to see what is going on. That leads to the problem pretty quickly.
0 Commenti
Vedere anche
Categorie
Scopri di più su Linear Algebra in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!