From: Michael on
Usually one calculates a polynomial using "polyfit" and then evaluates the polynomial at a certain position x using "polyval".

How do I do it the other way round? If I have the polynomial coefficients and a certain value but want to know the position x?

From a mathematical point of view, I would say there might be ambiguous solutions, which certainly will be a problem. But is there any function pre-implemented in MATLAB?
From: Bruno Luong on
"Michael " <michael.schmittNOSPAM(a)bv.tum.de> wrote in message <hot72c$19d$1(a)fred.mathworks.com>...
> Usually one calculates a polynomial using "polyfit" and then evaluates the polynomial at a certain position x using "polyval".
>
> How do I do it the other way round? If I have the polynomial coefficients and a certain value but want to know the position x?
>
> From a mathematical point of view, I would say there might be ambiguous solutions, which certainly will be a problem. But is there any function pre-implemented in MATLAB?

help ROOTS

Bruno
From: James Allison on
roots will only provide the zeros of a polynomial, not x for a given
y=f(x). fzero can do this, but is a more general method that does not
take advantage of your function being a polynomial. As you mentioned,
there may be multiple solutions to y=f(x) for a polynomial; fzero will
find a solution that is near the starting point you specify. Here is an
example:

% create a polynommial
y1 = [-1 8 17 19 10 -2 -7 -1 7 9];
x1 = 1:10;
p = polyfit(x1,y1,5);

% find values of x where polyval(p,x) = 5
y = 5; x0 = 1;
f = @(x) polyval(p,x) - y;
x = fzero(f,x0)

% try with other starting points:
x0 = 2;
x = fzero(f,x0)

x0 = 5;
x = fzero(f,x0)

x0 = 8;
x = fzero(f,x0)

The results are:

x =
0.3507
x =
1.7616
x =
5.4230
x =
8.7112

which each correspond to a point where the polynomial is equal to y=5.

-James

Michael wrote:
> Usually one calculates a polynomial using "polyfit" and then evaluates
> the polynomial at a certain position x using "polyval".
>
> How do I do it the other way round? If I have the polynomial
> coefficients and a certain value but want to know the position x?
>
> From a mathematical point of view, I would say there might be ambiguous
> solutions, which certainly will be a problem. But is there any function
> pre-implemented in MATLAB?
From: Walter Roberson on
James Allison wrote:
> roots will only provide the zeros of a polynomial, not x for a given
> y=f(x).

Since it is a polynomial, you can roots() of f(x)-y
From: Bruno Luong on
James Allison <james.allison(a)mathworks.com> wrote in message <hot9lg$d67$1(a)fred.mathworks.com>...
> roots will only provide the zeros of a polynomial, not x for a given
> y=f(x).

P(x) = f(x)-y is polynomial, and what is the root of P(x)?

Bruno