MATLAB Answers

How to return the original polynomial from the calculated roots

3 views (last 30 days)
Basim Touqan
Basim Touqan on 28 Apr 2021
Answered: Dyuman Joshi on 1 May 2021
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 =
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

Answers (1)

Dyuman Joshi
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];

Community Treasure Hunt

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

Start Hunting!

Translated by