Asked by VipVik
on 1 May 2016

How do I find all the roots of this equation?

x^3 - x^2 + x + x^0.5 - 10 = 0

fzero only gives one root

and I don't know how to put x^0.5 in roots

Is there a function to find all roots? Or do I need to make a loop with fzero?

Answer by John D'Errico
on 1 May 2016

You could make it easier if you bothered to tell us that you lack the symbolic toolbox. You could make it even easier if you just got that tool.

R1 = solve(x^3 - x^2 + x + sqrt(x) - 10 == 0)

Warning: Cannot solve symbolically. Returning a numeric approximation instead.

> In solve (line 303)

R1 =

2.2434806907853598069234052027194

As solve points out, this is effectively a polynomial of order higher than 4. Therefore there will be NO analytical solution available. So just use vpasolve. We can kill off the root we just found, then repeat.

R2 = vpasolve((x^3 - x^2 + x + sqrt(x) - 10)/(x-R1) == 0)

R2 =

- 0.57850464588438859334157837785007 - 1.9364293603758539638535819453716i

Rinse and repeat...

R3 = vpasolve((x^3 - x^2 + x + sqrt(x) - 10)/(x-R1)/(x-R2) == 0)

R3 =

- 0.57850464588438859334157837785007 + 1.9364293603758539638535819453716i

R4 = vpasolve((x^3 - x^2 + x + sqrt(x) - 10)/(x-R1)/(x-R2)/(x-R3) == 0)

R4 =

Empty sym: 0-by-1

So vpasolve now gives up the ghost.

Oh, yes, you don't have the symbolic toolbox. So use roots. You say that you cannot use roots, because of the sqrt? Not true.

If we transform it using z = sqrt(x), then the polynomial is of the form

z^6 - z^4 + z^2 + z - 10 == 0

Thus...

rz = roots([1 0 -1 0 1 1 -10]).^2

rz =

2.47945022249623 + 0i

-0.782960810756404 - 1.94637511714628i

-0.782960810756404 + 1.94637511714628i

-0.578504645884386 + 1.93642936037585i

-0.578504645884386 - 1.93642936037585i

2.24348069078536 + 0i

Now, some of those presumed roots will not be so. They will be spurious solutions introduced by the sqrt transformation. Drop the extraneous non-roots of the original problem.

rz.^3 -rz.^2 +rz + sqrt(rz) - 10

ans =

3.14925402119063 + 0i

1.62172220765055 - 2.40038042022762i

1.62172220765055 + 2.40038042022762i

-3.01980662698043e-14 - 1.82076576038526e-14i

-3.01980662698043e-14 + 1.82076576038526e-14i

2.1316282072803e-14 + 0i

As you can see, the first three roots were not truly roots. Drop them, and you have the same result that vpasolve gave you, but to a lower precision.

Had the problem been a nastier one, with some power other than a sqrt, it would have been more difficult, but there are still ways to solve the problem.

Sign in to comment.

Answer by Azzi Abdelmalek
on 1 May 2016

Edited by Azzi Abdelmalek
on 1 May 2016

solve('x^3 - x^2 + x + x^0.5 - 10 ')

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.