want to get only real roots using solve() function
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Guys I am using solve() function to solve an equation but I am getting 4 imaginary and one real root. I want to discard all the imaginary ones and keep only the real root. Can someone please guide me on that??? Example:
syms x
solve(x^5+4*x+4==0,x)
Output: ans =
-0.87313412488690536355061732751834
1.1872103327214796620635557946667 + 1.0342703166631692936215196761615*i
- 0.75064327027802698028824713090754 - 1.1333138159507348236526591082682*i
- 0.75064327027802698028824713090754 + 1.1333138159507348236526591082682*i
1.1872103327214796620635557946667 - 1.0342703166631692936215196761615*i
any method to keep only first answer and discard all the others???
0 commentaires
Réponses (1)
Star Strider
le 12 Oct 2016
Use ‘logical indexing’:
syms x
x_sol = vpasolve(x^5+4*x+4==0,x);
idx = abs(imag(x_sol)) < eps;
Real_Roots = x_sol(idx)
Real_Roots =
-0.87313412488690536355061732751834
0 commentaires
Voir également
Catégories
En savoir plus sur Calculus 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!