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

1 vue (au cours des 30 derniers jours)
daniel choudhry
daniel choudhry le 7 Oct 2020
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

Réponse acceptée

Walter Roberson
Walter Roberson le 7 Oct 2020
d = (-1)^s;;
Maybe you should be multiplying that by A ?

Plus de réponses (0)

Catégories

En savoir plus sur Octave dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by