# Polynomial passing through two points with specific tangents

How can I calculate a Polynomial that passes through the origin and a given point (P) having given tangents at the origin (Ot) and the given point (Op)?

The given point will always be to the right of the origin (Px > 0). The polynomial should be a function of x (i.e. it moves from left to right).

I believe a 3rd degree polynomial will always fit these constraints, but I'm not certain.

I am looking for a function f( x, Px, Py, Ot, Pt ) = ? which plots a polynomial for x, satisfying the four given values.

When x = 0,   f()   = 0
When x = Px,  f()   = Py
When x = 0,   f'()  = Ot
When x = Px,  f'()  = Pt

-
The slope of a tangent line is given by the derivative, so you want to solve a system of the form $$f(0)=0, f(p)=q,$$ $$f'(0)=a, f'(p)=b.$$ If you write out the polynomial $f$ in terms of its coefficients and then compute what the above equations should be, you'll have a linear system in terms of the coefficients. You'll have four equations, so to ensure a solution you'll want four unknowns i.e. a third-degree polynomial. –  anon Aug 10 '11 at 23:35
Like anon said. But please start from f(x)=ax+cx^2+dx^3, to solve only two equations for two unknowns (c and d). –  Did Aug 10 '11 at 23:52
@anon: You could put that in the answer box. I'd vote for it –  Ross Millikan Aug 11 '11 at 0:21

The slope of a tangent line is the derivative, so you want to solve a system of the form ($p\ne 0$)

$$f(0)=0, f(p)=q,$$ $$f'(0)=a, f'(p)=b.$$

The coefficients of $f$ are the unknowns, and we have four equations making a linear system for the coefficients. To ensure a solution, we need also four unknowns i.e. a degree $3$ polynomial. From the left two conditions we know that $f(x)=dx^3+cx^2+ax$. The right two conditions then are

$$\begin{pmatrix}p^3 & p^2\\3p^2 & 2p\end{pmatrix} \begin{pmatrix}d\\c\end{pmatrix}=\begin{pmatrix}q-ap\\b-a\end{pmatrix}.$$

Solving,

$$\begin{pmatrix}d\\c\end{pmatrix}=-\frac{1}{p^4}\begin{pmatrix}2p & -p^2\\-3p^2 & p^3\end{pmatrix}\begin{pmatrix}q-ap\\b-a\end{pmatrix}.$$

Thus we have

$$f(x,p,q,a,b)=-\frac{2p(q-ap)-p^2(b-a)}{p^4}x^3-\frac{-3p^2(q-ap)+p^3(b-a)}{p^4}x^2+ax.$$

EDIT: Also, the polynomial can be quadratic or linear if and only if the corresponding coefficients above vanish appropriately. To see this, solve the quadratic case to get the condition

$$\frac{q-ap}{p^2}=\frac{b-a}{2p},$$

which is equivalent to $d=0$. By geometry, the linear case occurs when $a=b=p/q$, which can also be shown as logically equivalent to $d=c=0$.

-
In general one needs to solve a (confluent) Vandermonde system to do Hermite interpolation, but as can be seen in anon's answer, specially arranged data can allow for shortcuts. –  Ｊ. Ｍ. Aug 11 '11 at 2:25

This is a very well-studied problem. In addition to anon's comment (which he expanded into an answer while I was writing this up), I wanted to direct you to this class of problems

This is a polynomial interpolation problem, and when you know the values of the function and some or all of its derivatives at these points, this is called Hermite Interpolation. Atkinson's Introduction to Numerical Analysis covers this topic very well and has several very instructive problems on it.

-
Addendum: in fact, OP's very problem (i.e. cubics with known tangents) turns up a lot in computer graphics (e.g. splines) among other things. –  Ｊ. Ｍ. Aug 11 '11 at 2:23