Skip to content

Instantly share code, notes, and snippets.

@trueharuu
Created September 12, 2023 19:22
Show Gist options
  • Save trueharuu/2e5273224349a1e9d411eb2eed287bb7 to your computer and use it in GitHub Desktop.
Save trueharuu/2e5273224349a1e9d411eb2eed287bb7 to your computer and use it in GitHub Desktop.

Prompt:

Given $a, b, c, d \in R$

Find a function $f(x)$ such that:

$f'(a) = 0$

$f'(c) = 0$

$f(a) = b$

$f(c) = d$

Solution

Cubic form is $k \cdot g(x) + h$

For $f'(a)$ and $f'(c)$ to be equal to $0$, $a$ and $c$ must be the roots of a polynomial:

$f'(x) = (x - a)(x - c)$

Integrate:

$g(x) = \int (x - a)(x - c) dx$

$g(x) = \int (x^2 - ax - cx + ac) dx$

$g(x) = \int x^2 dx - \int ax dx - \int cx dx + \int ac dx$

Factor out constants:

$g(x) = \int x^2 dx - a\int x dx - c\int x dx + ac\int 1 dx$

$g(x) = \frac{x^3}{3} - \frac{ax^2}{2} - \frac{cx^2}{2} + acx$

$g(x) = \frac{x^3}{3} - \frac{ax^2 - cx^2}{2} + acx$

$g(x) = \frac{x^3}{3} - \frac{x^2(a-c)}{2} + acx$

Factor out $x$:

$g(x) = x(\frac{x^2}{3} - \frac{x(a-c)}{2} + ac)$

$g(x) = \frac{6x(\frac{x^2}{3} - \frac{x(a-c)}{2} + ac)}{6}$

$g(x) = \frac{x(2x^2 - 3x(a-c) + 6ac)}{6}$

Return to original equation: $kx(\frac{x^2}{3} - \frac{x(a-c)}{2} + ac) + h$

Note that:

$f(a) = b$

$ka(\frac{a^2}{3} - \frac{a(a-c)}{2} + ac) + h = b$

$k(\frac{a^3}{3} - \frac{a^2(a-c)}{2} + a^2c) + h = b$

$f(c) = d$

$kc(\frac{c^2}{3} - \frac{c(a-c)}{2} + ac) + h = d$

$k(\frac{c^3}{3} - \frac{c^2(a-c)}{2} + ac^2) + h = d$

Solve system of equations by subtraction:

$b - d = f(a) - f(c)$

$b - d = (k(\frac{a^3}{3} - \frac{a^2(a-c)}{2} + a^2c) + h) - (k(\frac{c^3}{3} - \frac{c^2(a-c)}{2} + ac^2) + h)$

Ignoring $h$ as it does not change the value of $k$ in any way:

$b - d = (k(\frac{a^3}{3} - \frac{a^2(a-c)}{2} + a^2c)) - (k(\frac{c^3}{3} - \frac{c^2(a-c)}{2} + ac^2))$

Factor out $k$.

$b - d = k((\frac{a^3}{3} - \frac{a^2(a-c)}{2} + a^2c) - (\frac{c^3}{3} - \frac{c^2(a-c)}{2} + ac^2))$

Factor out $-1$ from second term.

$b - d = k(\frac{a^3}{3} - \frac{a^2(a-c)}{2} + a^2c - \frac{c^3}{3} - \frac{c^2(a-c)}{2} - ac^2)$

Group fractions.

$b - d = k(\frac{a^3 - c^3}{3} - \frac{a^2(a-c) - c^2(a - c)}{2} + ac(a - c))$

$b - d = k(\frac{a^3 - c^3}{3} - \frac{(a^2 - c^2)(a - c)}{2} + ac(a - c))$

$b - d = k(\frac{(a - c)(a^2 + ac + c^2)}{3} - \frac{(a^2 - c^2)(a - c)}{2} + ac(a - c))$

$b - d = k(a - c)(\frac{a^2 + ac + c^2}{3} - \frac{a^2 - c^2}{2} + ac)$

$b - d = k(a - c)(\frac{a^2 + ac + c^2}{3} - \frac{(a + c)(a + c)}{2} + ac)$

[DNF] but,

$k = -\frac{6(b - d)}{(a - c)^3}$

$h = \frac{b + d}{2} - \frac{(b - d)(a + c)(a^2 + c^2 - 4ac)}{2(a - c)^3}$

Finally,

$f(x) = -\frac{6(b - d)}{(a - c)^3}(\frac{x(2x^2 - 3x(a-c) + 6ac)}{6}) + (\frac{b + d}{2} - \frac{(b - d)(a + c)(a^2 + c^2 - 4ac)}{2(a - c)^3})$

$f(x) = -\frac{(b - d)}{(a - c)^3}(x(2x^2 - 3x(a-c) + 6ac) + (\frac{b + d}{2} - \frac{(b - d)(a + c)(a^2 + c^2 - 4ac)}{2(a - c)^3})$

$f(x) = -\frac{(b - d)(x(2x^2 - 3x(a-c) + 6ac)}{(a - c)^3} + \frac{b + d}{2} - \frac{(b - d)(a + c)(a^2 + c^2 - 4ac)}{2(a - c)^3}$

$f(x) = -\frac{(b - d)(x(2x^2 - 3x(a-c) + 6ac)}{(a - c)^3} + \frac{(b + d)(a - c)^3}{2(a - c)^3} - \frac{(b - d)(a + c)(a^2 + c^2 - 4ac)}{2(a - c)^3}$

$f(x) = -\frac{(b - d)(x(2x^2 - 3x(a-c) + 6ac)}{(a - c)^3} + \frac{(b + d)(a - c)^3 - (b - d)(a + c)(a^2 + c^2 - 4ac)}{2(a - c)^3}$

$f(x) = -\frac{2(b - d)(x(2x^2 - 3x(a-c) + 6ac)}{2(a - c)^3} + \frac{(b + d)(a - c)^3 - (b - d)(a + c)(a^2 + c^2 - 4ac)}{2(a - c)^3}$

$f(x) = -\frac{2(b - d)(x(2x^2 - 3x(a-c) + 6ac) + (b + d)(a - c)^3 - (b - d)(a + c)(a^2 + c^2 - 4ac)}{2(a - c)^3}$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment