Afficher commentaires plus anciens
how to find a roots of a cubic equation in matlab?
Réponses (1)
Andrei Bobrov
le 25 Fév 2012
eg
use roots
%polynomial x^3-6*x^2-50*x-4
p = [1 -6 -50 -4]
out = roots(p)
use solve and Symbolic Math Toolbox
syms x
out2 = solve(x^3-6*x^2-50*x-4)
vpa(out2,6)
on Nasir comment
out = zeros(3,...);
for j1 = 1:....
B = ...
A = ...
out(:,j1) = roots([1, B-1, A-3*B^2, A*B-B^2-B^3]);
end
5 commentaires
Nasir Qazi
le 25 Fév 2012
Walter Roberson
le 25 Fév 2012
Careful, there would be three roots for each cubic, so you would not be able to store the output of roots() in to a single array location out(j1)
Andrei Bobrov
le 25 Fév 2012
Thank you Walter! Corrected.
Nasir Qazi
le 27 Fév 2012
Walter Roberson
le 27 Fév 2012
I think we would need to see the code.
Catégories
En savoir plus sur Symbolic Math Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!