aralar
aralar

Reputation: 3120

MATLAB: evaluate a polynomial based on zeros and initial condition

On MATLAB, it's possible to get the coefficients of a polynomial p based on its roots through

r = [5 6 18];
p = poly(r);

My problem requires that the coefficients of the polynomial satisfy f(0) = -2, however, and I don't know how to integrate this requirement into the command above. I have access to polyval() as well, but I'm not sure how that'd help.

Thank you for your help!

Upvotes: 0

Views: 105

Answers (1)

David
David

Reputation: 8459

For this specific case (where f(0) is not a root of the equation), you can simply do the following:

r=[5 6 18]
p=poly(r)
f0=-2
p=p*f0/polyval(p,0) %// just scaling p so that f(0)=-2
polyval(p,0) %// checking the answer

But in general, you can use polyfit

p2=polyfit([0 r],[-2 0 0 0],3) %// f(0)=-2 and f(r)=0 for r=5,6,18

Upvotes: 1

Related Questions