want to get only real roots using solve() function
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Star Strider
2016-10-12
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!