Computing determinant of matrix A using LU factorization
3 次查看(过去 30 天)
显示 更早的评论
I must compute the determinant of an nxn matrix A using LU factorization. I have already calculated L and U in a different 'lufact' function. For some reason though, my funcion for computing the determinant of A, which is just equal to the product of the diagonal entries of matrix U is not working.
seed = 7;
rng(seed)
A = randn(n,n);
[L,U] = lufact(A);
function f = determ(A)
%Computing determinant of A
f = prod(diag(U));
end
1 个评论
the cyclist
2019-10-8
One weirdness here. If your function definition is really
function f = determ(A)
%Computing determinant of A
f = prod(diag(U));
end
then that is going to throw an error, because you don't pass in U. So, maybe you are not really calculating with the inputs you expect?
回答(1 个)
the cyclist
2019-10-8
编辑:the cyclist
2019-10-8
If I use the lu function from MATLAB (instead of your lufact function), I get the expected result. So, I'd double-check your LU factorization code.
seed = 7;
n = 5;
rng(seed)
A = randn(n,n);
[L,U] = lu(A);
f = prod(diag(U))
d = det(A)
f =
-8.0745
d =
-8.0745
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!