My code is not working and i cannot figure out why not?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
daniel choudhry
le 7 Oct 2020
Réponse apportée : Walter Roberson
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
0 commentaires
Réponse acceptée
Walter Roberson
le 7 Oct 2020
d = (-1)^s;;
Maybe you should be multiplying that by A ?
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Linear Algebra 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!