vpa doesnt transform the roots of a polynomial equation to numerical results
2 views (last 30 days)
Show older comments
syms x k
eq1 = x^3 - x*k^2 + 2*k*x^2 + 2*k^3 == 0;
sol = solve(eq1,x);
vpa(sol)
in the code above, although i use the vpa command i still get the following result:
ans =
root(z^3 + 2*k*z^2 - k^2*z + 2*k^3, z, 1)
root(z^3 + 2*k*z^2 - k^2*z + 2*k^3, z, 2)
root(z^3 + 2*k*z^2 - k^2*z + 2*k^3, z, 3)
0 Comments
Answers (2)
John D'Errico
on 5 May 2020
Edited: John D'Errico
on 5 May 2020
You want numerical roots, for completely general k? Brute force is a problem, since those roots would still be a function of k. so vpa still probably sees k in there and gives up.
However, if you think about what you have written, then you might try the transformation
y = x/k
Now what happens? As long as k is non-zero, then just divide that equation by k^3. Can you now write it in terms of y? Do you even need the symbolic toolbox to do that? Yes, you could use a substitution, and then call vpasolve appropriately. In terms of y, you now have:
y^3 + 2*y^2 - y + 2 = 0
xsol = vpasolve( y^3 + 2*y^2 - y + 2 == 0)*k
xsol =
-2.658967081916994079346775156784*k
k*(0.32948354095849703967338757839201 - 0.80225455755741079349558767590419i)
k*(0.32948354095849703967338757839201 + 0.80225455755741079349558767590419i)
Just as easy is to use roots. then multiply by k to recover x, as a function of k. I suppose that leaves the numbers in a rational number form though.
x = roots([1 2 -1 2])*k
x =
-(2993730789827947*k)/1125899906842624
k*(5935447809141593/18014398509481984 + 7226066652943669i/9007199254740992)
k*(5935447809141593/18014398509481984 - 7226066652943669i/9007199254740992)
0 Comments
Ameer Hamza
on 5 May 2020
Edited: Ameer Hamza
on 5 May 2020
You need to specify the value of 'k' to get a numerical solution
syms x k
eq1 = x^3 - x*k^2 + 2*k*x^2 + 2*k^3 == 0;
sol = solve(eq1,x);
vpa(subs(sol,k,1))
Result
ans =
0.32948354095849703967338757839201 - 0.80225455755741079349558767590419i
0.32948354095849703967338757839201 + 0.80225455755741079349558767590419i
-2.658967081916994079346775156784
0 Comments
See Also
Categories
Find more on Linear Algebra 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!