want to get only real roots using solve() function
4 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Star Strider
on 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 Comments
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!