Find Quartic Function Given Constraints

Find Quartic Function Given Constraints
$\begingroup$

I have a generic quartic function

$$f(x) = a + b x + c x^2 + d x^3 + e x^4$$

and I want to find the values for $a$, $b$, $c$, $d$ and $e$ such that the function has two minima at $x = 0$ and $x = 1$ and one maximum at a given $x = x_e$ (which must be calculated). Other restrictions to the problem are that $f(0) = 0$, $f(1) = 0.5$ and $f(x_e) = 1$.

At first, it is easy to predict that $a = 0$ and $b = 0$. But I do not know how to find the other values of $c$, $d$ and $e$. Perhaps making use of Lagrange multipliers is a way, but I can't figure it out how to solve the problem this way.

I'm trying to use IPython with SymPy to solve and plot the problem, so preferably a solution showed with these packages would be great.

$\endgroup$
11

1 Answer

$\begingroup$

From $f(0) = 0$, we conclude that $\color{blue}{a = 0}$. From the fact that $f$ has two local minima and one local maximum, we conclude that $\color{blue}{e > 0}$. Taking the 1st derivative of $f$, we obtain

$$f ' (x) = b + 2 c x + 3 d x^2 + 4 e x^3$$

From $f ' (0) = 0$, we conclude that $\color{blue}{b = 0}$. From $f ' (1) = 0$ and $f (1) = \frac 12$, we obtain a system of $2$ linear equations in unknowns $c$, $d$ and $e$

$$\begin{array}{rl} 2 c + 3 d + 4 e &= 0\\ c + d + e &= \frac 12\end{array}$$

Let us introduce parameter $t > 0$. Let $\color{blue}{e = t}$. Hence, $\color{blue}{c = t + \frac 32}$ and $\color{blue}{d = -1 - 2 t}$. Thus,

$$f ' (x) = (2 t + 3) x + 3 (-1 - 2 t) x^2 + 4 t x^3 = x \left( 2 t + 3 - 3 (1 + 2 t) x + 4t x^2 \right)$$

After some tedious work, we conclude that the maximum is attained at

$$x_{\max} := \frac{2 t + 3}{4t}$$

Since $f (x_{\max}) = 1$, we eventually obtain the quartic equation

$$(2 t + 3)^3 (2 t - 1) - 256 t^3 = 0$$

Using SymPy to solve the quartic equation above:

>>> from sympy import *
>>> t = Symbol('t')
>>> p = (2*t + 3)**3 * (2*t - 1) - 256*t**3
>>> roots = solve(p,t)

Print the $4$ roots in floating-point:

>>> for r in roots:
        r.evalf()


0.401923788646684 - 0.431895218164327*I
0.401923788646684 + 0.431895218164327*I
11.6136005841302
-0.417448161423609

Print the positive root:

>>> roots[2].simplify()
3*sqrt(3)/2 + 3 + sqrt(72 + 42*sqrt(3))/2

Since only one root is real and positive, we conclude that the value of parameter $t$ is

$$\boxed{ \quad t = \frac{3 \sqrt{3}}{2} + 3 + \frac{1}{2} \sqrt{72 + 42 \sqrt{3}} \approx 11.6136005841302 \quad }$$

Let us verify:

>>> from sympy import *
>>> x = Symbol('x')
>>> t = 3*sqrt(3)/2 + 3 + sqrt(72 + 42*sqrt(3))/2
>>> f = (t + 1.5)*x**2 - (1+2*t)*x**3 + t*x**4

Let us check the derivatives:

>>> diff(f,x).subs(x,0)
0
>>> diff(f,x).subs(x,1)
0
>>> diff(f,x).subs(x,(2*t+3)/(4*t))
-3*(3*sqrt(3) + 7 + sqrt(72 + 42*sqrt(3)))*(3*sqrt(3) + 9 + sqrt(72 + 42*sqrt(3)))**2/(6*sqrt(3) + 12 + 2*sqrt(72 + 42*sqrt(3)))**2 + 4*(3*sqrt(3)/2 + 3 + sqrt(72 + 42*sqrt(3))/2)*(3*sqrt(3) + 9 + sqrt(72 + 42*sqrt(3)))**3/(6*sqrt(3) + 12 + 2*sqrt(72 + 42*sqrt(3)))**3 + 2*(3*sqrt(3)/2 + 4.5 + sqrt(72 + 42*sqrt(3))/2)*(3*sqrt(3) + 9 + sqrt(72 + 42*sqrt(3)))/(6*sqrt(3) + 12 + 2*sqrt(72 + 42*sqrt(3)))

The 3rd one is messy. In floating-point:

>>> diff(f,x).subs(x,(2*t+3)/(4*t)).evalf()
0.e-123

which is zero. So far, so good! Let us check if $f (1) = \frac 12$:

>>> f.subs(x,1)
0.500000000000000

It works! Lastly, quartic function $f$ is

$$\boxed{\quad f (x) = \frac 12 \left( 3 \sqrt{3} + 6 + \sqrt{72 + 42 \sqrt{3}} \right) x^{4} - \left(3 \sqrt{3} + 7 + \sqrt{72 + 42 \sqrt{3}}\right) x^{3} + \quad \\ \qquad\quad + \frac 12 \left( 3 \sqrt{3} + 9 + \sqrt{72 + 42 \sqrt{3}} \right) x^{2} \quad}$$

Plotting the graph of function $f$,

The local maximum is attained at

$$\frac{2t+3}{4t} = \frac{1}{2} \left( \dfrac{3 \sqrt{3} + 9 + \sqrt{72 + 42 \sqrt{3}}}{3 \sqrt{3} + 6 + \sqrt{72 + 42 \sqrt{3}}} \right) \approx 0.564579455317661$$

$\endgroup$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.