want to get only real roots using solve() function

4 Ansichten (letzte 30 Tage)
Abdul Asad
Abdul Asad am 12 Okt. 2016
Beantwortet: Star Strider am 12 Okt. 2016
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???

Antworten (1)

Star Strider
Star Strider am 12 Okt. 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

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by