# I Procedurally generated polynomial functions

1. Jul 12, 2016

### JMS1

I'm a programmer looking for a way to create polynomial equations from a list of x intercepts and local maxima.

For the sake of discussion we can begin with a function of degree 4. The scale and position of the curve is unimportant so for simplicity's sake the curve can always have x intercepts at 1 and -1. That leaves the declaration of one local maximum to create a unique equation. If I want that maximum to be (0,0) then the equation takes the form (x-1)(x+1)(x)(x). Moving the maximum along the x axis is simple. For maximum at (a,0) use the formula (x-1)(x+1)(x-a)(x-a) for any 'a' where 1>a>-1. Creating an equation where the local maximum is on the y axis is also easy where a maximum at (0,-b) can be given by the equation (x-1)(x+1)(x-bi)(x+bi) for any b where 1>b>0

The problems arise when trying to use a maximum not on a zero axis. for example trying to create a local maximum at (0.2,-0.2) using the equation (x-1)(x+1)(x-.2-.2i)(x-.2+.2i) the local maximum is actually at (0.256,-0.190). Not exactly what I was looking for. So what would be a generalized formula which would give me a local maximum at (a,-b)?

2. Jul 13, 2016

### Staff: Mentor

You could operate with $f(x) = a_n x^n + \dots + a_1x+a_0$ instead and formulate your conditions in terms of derivatives of $f$, i.e. in conditions on the $a_i$.

3. Jul 13, 2016

### JMS1

I could, but how?

Taking the example I gave of the function $f(x)=(x-1)(x+1)(x-.2-.2i)(x-.2+.2i)$, or otherwise written $f(x)=x^4-.4x^3-.76x^2+.4x-.24$, I get the derrivitive $f'(x)=4x^3-1.2x^2-1.52x+.4$. taking the value at $x=.2$ I get $y=.08$. Subtracting this from the derivative I get $f'(x)=4x^3-1.2x^2-1.52x+.32$. The integral of this is $f(x)=x^4-.4x^3-.76x^2+.32x$. Evaluating this equation at $x=.2$ I get $y=.032$. Now subtracting $.232$ from the function I get $f(x)=x^4-.4x^3-.76x^2+.32x-.232$. Evaluating this function I do indeed have a local maximum at $(0.2,-0.2)$. However while I've been changing the function to match the local maximum I've managed to move the $x$ intercepts from my standard $-1, 1$, to $-0.972, 1.041$.

In the end I've traded one two-dimensional discrepancy for two one-dimensional discrepancies. Calculus may be the way forward with this, but If it is I still don't know how to apply it.

4. Jul 13, 2016

### Staff: Mentor

Let's gather what you have. You are looking for a polynomial $f$ of $\deg(f) = 4 \; , \; f(1) = f(-1) = 0 \; , \; f(0.2) = -0.2$ and the maximum condition gives $f'(0.2) = 0$ and $f''(0.2) < 0.$
These conditions on the coefficients $a_i$ of $f$ mean:
$a_0 + a_1 + a_2 + a_3 + a_4 = 0$
$a_0 - a_1 + a_2 - a_3 + a_4 = 0$
$a_0 + a_1 \cdot (0.2)^1 + a_2 \cdot (0.2)^2 + a_3\cdot (0.2)^3 + a_4\cdot (0.2)^4 = -0.2$
$a_1 + 2a_2 \cdot (0.2)^1 + 3a_3\cdot (0.2)^2 + 4a_4\cdot (0.2)^3 = 0$
$a_2 + 3a_3\cdot (0.2)^1 + 6a_4\cdot (0.2)^2 < 0$
Now any solution to these conditions gives you a required polynomial $f$. In general there can be more than one solution or even none.

5. Jul 13, 2016

### chiro

Hey JMS1.

Following on from fresh_42's advice, I'd list the constraints one by one with whatever information you have and then rectify that system.

If you don't have a full rank system then you will get multiple solutions.

Also - are you trying to do anything besides have a maximum at a point along with the intercepts?

If you get an inconsistency then it means you will probably get a function that is inconsistent with the constraints (like how a linear system when row reduced has a bunch of zero's in a row but a non-zero element in the final column). That's how you tell for linear systems but for non-linear you get a complex solution when a consistent one would result in real numbers.

6. Jul 13, 2016

### Stephen Tashi

How many points specifying local maxima will you have for each polynomial ? - just one given (x=a, y=b = local max) point per polynomial or several?

7. Jul 14, 2016

### JMS1

It works!

It looks simple and robust enough to be applied to a general case, thanks.

BTW: for future reference or google searching for help, what would you call this system?

Last edited: Jul 14, 2016
8. Jul 14, 2016

### JMS1

For even polynomials I have $x$ intercepts at $-1$ and $1$. For odd polynomials I put a double $x$ intercept at $1$ or in other words it's both an $x$ intercept and a zero slope point. . The scalar for the highest order term or $a_n$ is always $1$. That leaves $n-2$ degrees of freedom for even degree polynomials and $n-3$ degrees of freedom for odd degree polynomials. Each local maximum fixes $2$ degrees of freedom, so for $n=4$ and $n=5$ I need one local maximum. for $n=6$ and $n=7$ I need 2 local maxima, and so on.