My code is not working and i cannot figure out why not?
조회 수: 1 (최근 30일)
이전 댓글 표시
I need to put this into my command window in order to generate my answer d, but my d is not working and i dont know how to fix my d inside my code.
>>rand('seed',1)
>>A = rand(10,10);
>>d = my_det(A)
>>dd = det(A)
>>abs(d-dd)/abs(dd)
function d = my_det(A)
n = size(A,1);
s = 0;
% Gauss_PP:
for k = 1:n-1
r = k;
for j = k+1:n
if abs(A(j,k))> abs(A(k,k))
T=A(k,:);
A(k,:)=A(j,:);
A(j,:)=T;
end
end
while A(r,k) == 0 && r <= n
r=r+1;
end
if r > n+1
disp('A is not invertible');
break
else
if r ~= k
s = s+1;
t=A(k,:);
A(k,:)=A(s,:);
A(s,:)=t;
end
end
d = (-1)^s;;
if A(n,n)< n*10^(-15)
disp('A is not invertible');
return
end
end
댓글 수: 0
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Algebra에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!