How to return the original polynomial from the calculated roots
1 view (last 30 days)
Show older comments
Hi MATLAB experts,
I have following example:
Solve the equation 3x^2-2x-4
Create a vector to represent the polynomial, then find the roots.
>> p=[3 -2 -4];
>> r=roots(p)
ans =
1.5352
-0.8685
I find the roots and wanted to return back the same polynomial coefficients i used the follwing code:
>> poly(r)
ans =
1.0000 -0.6667 -1.3333
But the coefficients are not the same as the original polynomial coefficients.
The question is how to get or return the original polynomial coefficients?
Thanks & regards,
Basim Touqan
0 Comments
Answers (1)
Dyuman Joshi
on 1 May 2021
So, the coefficients are not the same, but they are similar.
%[1 -0.6667 -1.3333] is equal to [3 -2 4]/3.
This is because, poly() calculates equation in the form of x^2+b*x+c (a=1) instead of the generalised form a*x^2+b*x+c (i.e. the function is written in such a way).
If you want your solution to be in the generalised form, what you can do is multiply the equation with the first member of original equation.
p=[3 -2 4];
r=roots(p);
q=p(1)*poly(r);
0 Comments
See Also
Categories
Find more on Polynomials 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!