Equation behind solution by using function roots

Here is a minimum working example of my code:
f = [1 0 3 2];
V = roots(f);
It gives me the roots:
0.298035818991661 + 1.80733949445202i
0.298035818991661 - 1.80733949445202i
-0.596071637983321 + 0.00000000000000i
Here is the general solution to this equation:
How can I find out that matlab uses which of these equations for all of the three solutions?
In short: I want to find out not only the solution but also the equation used by Matlab to reach that solution. I know, I could manually input these values in the general solution and find the answer. But that will be cumbersome for many such equations. So I will require a compact solution.

 Accepted Answer

For a cubic, you can use the symbolic toolbox, and it will give you an analytical solution. Here is an easy way to get what you wanted.
roots(sym([1 0 3 2]))
ans =
(2^(1/2) - 1)^(1/3) - 1/(2^(1/2) - 1)^(1/3)
1/(2*(2^(1/2) - 1)^(1/3)) - (2^(1/2) - 1)^(1/3)/2 - (3^(1/2)*(1/(2^(1/2) - 1)^(1/3) + (2^(1/2) - 1)^(1/3))*1i)/2
1/(2*(2^(1/2) - 1)^(1/3)) - (2^(1/2) - 1)^(1/3)/2 + (3^(1/2)*(1/(2^(1/2) - 1)^(1/3) + (2^(1/2) - 1)^(1/3))*1i)/2
I've not bothered to see if it gives you the exact same form as the solution you show, but why bother? There are many ways to write any given expression.
However, go past the fourth order, and this will no longer work in general. All you can get then will be a numerical solution.

More Answers (1)

Please see http://www.mathworks.com/help/matlab/ref/roots.html#buo5imt-5 which describes the algorithm. It usually works numerically, not by equation. However, you can use
syms x1 x2 x3 x4
roots([x1 x2 x3 x4])
to see the generalized equation (which might not be used in some circumstances that would result in degeneracies.)

Categories

Products

Community Treasure Hunt

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

Start Hunting!