I cannot use the lugauss function to calculate L and U factors from matrix A. Please help!
1 回表示 (過去 30 日間)
古いコメントを表示
I have attached my operating code and here is the lugauss funciton:
function A=lugauss(A)
%LUGAUSS LU factorization without pivoting.
% A = LUGAUSS(A) stores an upper triangular matrix in
% the upper triangular part of A and a lower triangular
% matrix in the strictly lower part of A (the diagonal
% elements of L are 1).
[n,m]=size(A);
if n ~= m; error('A is not a square matrix'); else
for k = 1:n-1
for i = k+1:n
A(i,k) = A(i,k)/A(k,k);
if A(k,k) == 0, error('Null diagonal element '); end
j = [k+1:n]; A(i,j) = A(i,j) - A(i,k)*A(k,j);
end
end
end
0 件のコメント
回答 (1 件)
Satyam
2025 年 6 月 18 日
Hi Tianlan,
According to my understanding, since the value of x is not explicitly mentioned either in the code or the attached screenshot, it must be safe to assume the variable 'x' would be residing in workspace. Following this assumption, the error being faced in this code is probably due to 'x' being a vector having a dimension greater than one which is causing an inconsistency in concatenating the matrix.
A = [2 -2 0
x-2 2 0
0 -1 3]
To fix this issue you can adjust the dimensions of 'x' variable in order to match dimensions of matrix A. In the above case you'll need a single element variable 'x' to achieve that.
I hope it helps.
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!