Write a quadratic equation function
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi all,
I've been writing a function to solve a quadratic equation of the form ax^2 + bx + c. It works for quadratics where there are two real roots, but I want it to display NA for one of the roots when there is a repeated root or NA for both when there are no real roots. Not sure if I have to use an if statement or an if else statement?
Thanks for any help!
0 commentaires
Réponse acceptée
Honglei Chen
le 13 Nov 2014
Isn't this just depending on the value of b^2-4*a*c, something like
val = b^2-4*a*c;
if val > 0
% two roots
elseif val == 0
% one root, one NA
else
% NA
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Quadratic Programming and Cone Programming 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!