[Math] Finding coefficients of a function, given a list of points on the function

calculusfunctionspolynomials

Given $f(x) = ax^n + bx^{n-1} + … + cx + d$, a list of points, and a specification of a tangent line (point $p_t$ and equation) find $a, b, …, c, d$ s.t.

  1. $f(x)$ passes through each point
  2. the tangent line to $f(x)$ at $p_t$ satisfies the given equation

Now I know how to find a tangent line at a point on a function. What I'm less sure of is how to find the coefficients (and this is definitely not a linear regression problem).

This is a calculus I test question for which I don't have a specific example, and don't seem to know the magic google words to find one… In the actual case, I doubt this will be more than cubic in $x$, since this is a no-calculator test situation, but I'd still like to know the approach for arbitrary $n$

For the sake of argument, lets say the example polynomial is $ax^3 + bx^2 + cx + d$

Best Answer

The big trick in polynomial interpolation problems uses the function:

$$g(x)=(x-x_1)(x-x_2)\dots(x-x_n)$$

Note that this function is zero at each $x_n$ (and nowhere else). Also, $g'(x)=\sum_{i=1}^n \frac{g(x)}{x-x_i}$ (where the division is intended to cancel out the extra factor, so that it is defined even at each $x_i$).

If I divide $g(x)$ by $g(x^*)$ for some $x^*$ which is not equal to any $x_n$, I get a function that is $1$ at $x^*$ and $0$ at $x_i$. Adding functions of this form multiplied by scalars allows us to solve the problem of finding a polynomial which goes through $x_i,y_i$ (just take $\sum_{i=1}^ny_ig_i(x)$ where $g_i$ is zero for $x_j,j\ne i$ and one at $x_i$).

To get the derivative right at some specified $x^*$, just add to this expression $a\frac{g^*(x)}{{g^*}'(x^*)}$ where $g^*(x)$ is zero at each $x_i$ and at $x^*$; since $g^*(x)$ has a single root at $x^*$ its derivative there is nonzero, so the derivative of this part of the function is $a$, and we can set $a$ to be the desired derivative minus the derivative of the point-interpolation part of the function.


To give an example, let's find a polynomial such that $f(-2)=1$, $f(-1)=0$, $f'(0)=4$, $f(2)=2$. (I just made these numbers up.) First let's ignore the derivative part and construct functions that are zero at two of the points and one at the remaining point:

$$g_1(x)=\frac{(x+1)(x-2)}{(-2+1)(-2-2)}=\frac{x^2-x-2}{4}$$ $$g_2(x)=\frac{(x+2)(x-2)}{(-1+2)(-1-2)}=\frac{-x^2+4}{3}$$ $$g_3(x)=\frac{(x+2)(x+1)}{(2+2)(2+1)}=\frac{x^2+3x+1}{12}$$

Then $h(x)=g_1(x)+0g_2(x)+2g_3(x)=\frac{5x^2+3x-2}{12}$ satisfies $h(-2)=1$, $h(-1)=0$, $h(2)=2$. But it probably has the wrong derivative: $h'(x)=\frac{10x+3}{12}$, so $h'(0)=\frac14$ is not what we want. So let's construct a function which won't affect our other values, but has a nonzero derivative at $0$:

$$g^*(x)=(x+2)(x+1)(x-2)=x^3+x^2-4x-4\implies {g^*}'(x)=3x^2+2x-4$$

So ${g^*}'(0)=-4$. (It is possible for this to come out zero, in which case you can multiply the formula by $x-x^*$ to guarantee nonzero derivative at the expense of a higher degree.) Now the $h$ function is off from what we want by $4-\frac14=\frac{15}4$, while the adjustment function has derivative $-4$, so $-\frac{15}{16}{g^*}(x)$ has derivative $4-\frac14$ at $0$ and $f(x)=h(x)-\frac{15}{16}{g^*}(x)=-\frac{15}{16}x^3-\frac{25}{48}x^2+4x+\frac{43}{12}$ should do the trick.