# how to show A is non singular using GE and ut function files. im using this code and its showing error in line 3 which is n=length(b);

3 ビュー (過去 30 日間)
daniel choudhry 2020 年 9 月 13 日

function [U,c]=GE(A,b)
n=length(b);
for i=1:n-1
for k=n:-1:i+1
m= A(k,i)/A(i,i);
% A(k,i)=0;
% for j=2:4
A(k,:)=A(k,:)-A(i,:)*(m);
% end
b(k)=b(k)-b(i)*(m);
end
end
function x=ut_sys(U,c)
n=length(U);
x=zeros(n,1);
x(n)=c(n)/U(n,n);
for i=n-1:-1:1
s=0;
for j=n:-1:i+1
s =s+U(i,j)*x(j);
end
x(i) = (c(i)-s)/ U(i,i);
end

#### 1 件のコメント

daniel choudhry 2020 年 9 月 13 日
I'm using A=[1 1 0 3;2 1 -1 1;3 -1 -1 2; -1 2 6 -1]
b=[4;1;-3;4]

サインインしてコメントする。

### 採用された回答

Ayush Gupta 2020 年 9 月 16 日
Calculating determinant is a terribly inefficient thing for larger arrays. So, a nice alternative is to use the product of the diagonal elements of a specific matrix factorization of our square array. The best tool is to use rank. Thus, if the rank of an NxM matrix is less than min(N,M), then the matrix is singular. Suppose there is a matrix A, for which we want to check if it is singular or not, refer to the following code:
[N M] = size(A);
k = rank(A);
If(k<min(N,M))
%matrix is singular
end

サインインしてコメントする。

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!