Hello! How can I make MATLAB return the smallest, positive, purely real value from a column matrix?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, I would like to know how to make MATLAB return the smallest, positive, purely real value from a column matrix of length n which may contain complex and negative numbers.
So I already know how to get the length of the column matrix. In my case, the column matrix, (Uf), is made from the roots of a polynomial called T3. i.e.
Uf = roots(T3);
The polynomial, T3, is made up of convolutes of other polynomials which I have written in matrix form. If I input certain values for those smaller polynomials, the following function will not return the smallest positive value, and doesn't even know what the variable U_flutter is.
i = 1;
j = 0;
while i<=length(Uf);
notcomplex = isreal(Uf(i,1));
if notcomplex == 1 && Uf(i,1)>=0;
Ufl = Uf(i,1);
if Ufl < j;
U_flutter = Ufl;
else
j = Ufl;
end
else
if Uf(i,1)>0
U_flutter = j;
end
end
i = i + 1;
end
Thanks!
0 commentaires
Réponse acceptée
Matt Fig
le 28 Nov 2012
Modifié(e) : Matt Fig
le 28 Nov 2012
Uf = [0.84888 + 0.74301i
-1
0.31434 + 1.1736i
0.31434 - 1.1736i
3
-0.40027 - 1.2365i
-0.78795 + 0.20233i
5]
% Get the smallest, real, positive value if there is one.
idx = imag(Uf)==0 & real(Uf)>0;
sv = min(Uf(idx))
1 commentaire
Neil Chambers
le 24 Mar 2019
Modifié(e) : Neil Chambers
le 24 Mar 2019
This is very clever! Thank you!
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Operating on Diagonal Matrices 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!