want to get only real roots using solve() function
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!