My code is not working and i cannot figure out why not?

조회 수: 1 (최근 30일)
daniel choudhry
daniel choudhry 2020년 10월 7일
답변: Walter Roberson 2020년 10월 7일
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

채택된 답변

Walter Roberson
Walter Roberson 2020년 10월 7일
d = (-1)^s;;
Maybe you should be multiplying that by A ?

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Octave에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by