2013-11-05 20:30:34 +01:00
\documentclass [a4paper] { scrartcl}
\usepackage { amssymb, amsmath} % needed for math
2013-11-13 08:50:04 +01:00
\usepackage { mathtools} % \xRightarrow
2013-11-05 20:30:34 +01:00
\usepackage [utf8] { inputenc} % this is needed for umlauts
\usepackage [english] { babel} % this is needed for umlauts
\usepackage [T1] { fontenc} % this is needed for correct output of umlauts in pdf
\usepackage [margin=2.5cm] { geometry} %layout
\usepackage { hyperref} % links im text
\usepackage { braket} % needed for \Set
\usepackage { parskip}
\usepackage [colorinlistoftodos] { todonotes}
\usepackage { pgfplots}
\pgfplotsset { compat=1.7,compat/path replacement=1.5.1}
\usepackage { tikz}
2013-11-22 23:23:03 +01:00
\usepackage [framed,amsmath,thmmarks,hyperref] { ntheorem}
\usepackage { framed}
2013-12-05 23:27:17 +01:00
\usepackage { nicefrac}
2013-12-06 12:20:49 +01:00
\usepackage { siunitx}
2013-11-22 23:23:03 +01:00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define theorems %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\theoremstyle { break}
\setlength \theoremindent { 0.7cm}
\theoremheaderfont { \kern -0.7cm\normalfont \bfseries }
\theorembodyfont { \normalfont } % nicht mehr kursiv
2013-11-30 18:34:24 +01:00
\def \mdr { \ensuremath { \mathbb { R} } }
2013-12-05 23:27:17 +01:00
\renewcommand { \qed } { \hfill \blacksquare }
2013-11-30 18:34:24 +01:00
2013-11-23 01:19:21 +01:00
\newframedtheorem { theorem} { Theorem}
2013-11-22 23:23:03 +01:00
\newframedtheorem { lemma} [theorem]{ Lemma}
\newtheorem { plaindefinition} { Definition}
\newenvironment { definition} { \begin { plaindefinition} } { \end { plaindefinition} }
\newenvironment { definition*} { \begin { plaindefinition*} } { \end { plaindefinition*} }
\newtheorem { example} { Example}
\theoremstyle { nonumberplain}
\newtheorem { proof} { Proof:}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2013-11-05 20:30:34 +01:00
\title { Minimal distance to a cubic function}
\author { Martin Thoma}
\hypersetup {
pdfauthor = { Martin Thoma} ,
pdfkeywords = { } ,
pdftitle = { Minimal Distance}
}
\def \mdr { \ensuremath { \mathbb { R} } }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Begin document %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin { document}
\maketitle
\begin { abstract}
2013-11-25 08:13:14 +01:00
When you want to develop a selfdriving car, you have to plan which path
it should take. A reasonable choice for the representation of
paths are cubic splines. You also have to be able to calculate
how to steer to get or to remain on a path. A way to do this
2013-11-22 21:40:15 +01:00
is applying the \href { https://en.wikipedia.org/wiki/PID_ algorithm} { PID algorithm} .
2013-11-25 08:13:14 +01:00
This algorithm needs to know the signed current error. So you need to
be able to get the minimal distance of a point to a cubic spline combined with the direction (left or right).
2013-11-22 21:40:15 +01:00
As you need to get the signed error (and one steering direction might
be prefered), it is not only necessary to
2013-12-11 18:14:12 +01:00
get the minimal absolute distance, but might also help to get all points
2013-11-22 21:40:15 +01:00
on the spline with minimal distance.
In this paper I want to discuss how to find all points on a cubic
2013-11-05 20:30:34 +01:00
function with minimal distance to a given point.
2013-11-22 21:40:15 +01:00
As other representations of paths might be easier to understand and
to implement, I will also cover the problem of finding the minimal
distance of a point to a polynomial of degree 0, 1 and 2.
2013-11-05 20:30:34 +01:00
\end { abstract}
\section { Description of the Problem}
Let $ f: \mdr \rightarrow \mdr $ be a polynomial function and $ P \in \mdr ^ 2 $
2013-11-25 08:13:14 +01:00
be a point. Let $ d _ { P,f } : \mdr \rightarrow \mdr _ 0 ^ + $
2013-12-11 18:14:12 +01:00
be the Euklidean distance of a point $ P $ and a point $ \left ( x, f ( x ) \right ) $
on the graph of $ f $ :
2013-11-22 23:23:03 +01:00
\[ d _ { P,f } ( x ) : = \sqrt { ( x _ P - x ) ^ 2 + ( y _ P - f ( x ) ) ^ 2 } \]
2013-11-05 20:30:34 +01:00
2013-12-11 18:14:12 +01:00
Now there is finite set $ M = \Set { x _ 1 , \dots , x _ n } $ of minima for given $ f $ and $ P $ :
\[ M = \Set { x \in \mdr | d _ { P,f } ( x ) = \min _ { \overline { x } \in \mdr } d _ { P,f } ( \overline { x } ) } \]
2013-11-05 20:30:34 +01:00
2013-11-22 23:23:03 +01:00
But minimizing $ d _ { P,f } $ is the same as minimizing $ d _ { P,f } ^ 2 $ :
\begin { align}
d_ { P,f} (x)^ 2 & = \sqrt { (x_ P - x)^ 2 + (y_ P - f(x))^ 2} ^ 2\\
& = x_ p^ 2 - 2x_ p x + x^ 2 + y_ p^ 2 - 2y_ p f(x) + f(x)^ 2
\end { align}
2013-11-22 21:40:15 +01:00
2013-12-11 18:14:12 +01:00
\begin { theorem} [Fermat's theorem about stationary points]\label { thm:required-extremum-property}
Let $ x _ 0 $ be a local extremum of a differentiable function $ f: \mathbb { R } \rightarrow \mathbb { R } $ .
2013-11-23 01:18:22 +01:00
Then: $ f' ( x _ 0 ) = 0 $ .
2013-11-22 23:23:03 +01:00
\end { theorem}
\clearpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Constant functions %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2013-11-05 20:30:34 +01:00
\section { Minimal distance to a constant function}
2013-11-22 21:40:15 +01:00
Let $ f ( x ) = c $ with $ c \in \mdr $ be a constant function.
2013-11-05 20:30:34 +01:00
2013-11-05 20:47:41 +01:00
\begin { figure} [htp]
\centering
\begin { tikzpicture}
\begin { axis} [
legend pos=north west,
axis x line=middle,
axis y line=middle,
grid = major,
width=0.8\linewidth ,
height=8cm,
grid style={ dashed, gray!30} ,
xmin=-5, % start the diagram at this x-coordinate
xmax= 5, % end the diagram at this x-coordinate
ymin= 0, % start the diagram at this y-coordinate
ymax= 3, % end the diagram at this y-coordinate
axis background/.style={ fill=white} ,
xlabel=$ x $ ,
ylabel=$ y $ ,
tick align=outside,
minor tick num=-3,
enlargelimits=true,
tension=0.08]
\addplot [domain=-5:5, thick,samples=50, red] { 1} ;
\addplot [domain=-5:5, thick,samples=50, green] { 2} ;
2013-12-11 18:14:12 +01:00
\addplot [domain=-5:5, thick,samples=50, blue, densely dotted] { 3} ;
2013-11-05 20:47:41 +01:00
\addplot [black, mark = *, nodes near coords=$P$,every node near coord/.style={anchor=225}] coordinates { (2, 2)} ;
2013-11-22 21:40:15 +01:00
\addplot [blue, mark = *, nodes near coords=$P_{h,\text{min}}$,every node near coord/.style={anchor=225}] coordinates { (2, 3)} ;
\addplot [green, mark = x, nodes near coords=$P_{g,\text{min}}$,every node near coord/.style={anchor=120}] coordinates { (2, 2)} ;
\addplot [red, mark = *, nodes near coords=$P_{f,\text{min}}$,every node near coord/.style={anchor=225}] coordinates { (2, 1)} ;
2013-11-05 20:47:41 +01:00
\draw [thick, dashed] (axis cs:2,0) -- (axis cs:2,3);
\addlegendentry { $ f ( x ) = 1 $ }
\addlegendentry { $ g ( x ) = 2 $ }
\addlegendentry { $ h ( x ) = 3 $ }
\end { axis}
\end { tikzpicture}
2013-11-22 23:23:03 +01:00
\caption { Three constant functions and their points with minimal distance}
2013-11-22 21:40:15 +01:00
\label { fig:constant-min-distance}
2013-11-05 20:47:41 +01:00
\end { figure}
2013-11-05 20:30:34 +01:00
Then $ ( x _ P,f ( x _ P ) ) $ has
minimal distance to $ P $ . Every other point has higher distance.
2013-11-22 21:40:15 +01:00
See Figure~\ref { fig:constant-min-distance} .
2013-11-05 20:30:34 +01:00
2013-11-22 23:23:03 +01:00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Linear functions %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2013-11-05 20:30:34 +01:00
\section { Minimal distance to a linear function}
Let $ f ( x ) = m \cdot x + t $ with $ m \in \mdr \setminus \Set { 0 } $ and
2013-11-22 21:40:15 +01:00
$ t \in \mdr $ be a linear function.
2013-11-05 20:30:34 +01:00
2013-11-05 20:47:41 +01:00
\begin { figure} [htp]
\centering
\begin { tikzpicture}
\begin { axis} [
legend pos=north east,
axis x line=middle,
axis y line=middle,
grid = major,
width=0.8\linewidth ,
height=8cm,
grid style={ dashed, gray!30} ,
xmin= 0, % start the diagram at this x-coordinate
xmax= 5, % end the diagram at this x-coordinate
ymin= 0, % start the diagram at this y-coordinate
ymax= 3, % end the diagram at this y-coordinate
axis background/.style={ fill=white} ,
xlabel=$ x $ ,
ylabel=$ y $ ,
tick align=outside,
minor tick num=-3,
enlargelimits=true,
tension=0.08]
\addplot [domain=-5:5, thick,samples=50, red] { 0.5*x} ;
\addplot [domain=-5:5, thick,samples=50, blue] { -2*x+6} ;
\addplot [black, mark = *, nodes near coords=$P$,every node near coord/.style={anchor=225}] coordinates { (2, 2)} ;
\addlegendentry { $ f ( x ) = \frac { 1 } { 2 } x $ }
\addlegendentry { $ g ( x ) = - 2 x + 6 $ }
\end { axis}
\end { tikzpicture}
\caption { The shortest distance of $ P $ to $ f $ can be calculated by using the perpendicular}
2013-11-22 21:40:15 +01:00
\label { fig:linear-min-distance}
2013-11-05 20:47:41 +01:00
\end { figure}
2013-11-05 20:30:34 +01:00
2013-12-11 18:14:12 +01:00
Now you can drop a perpendicular $ f _ \bot $ through $ P $ on $ f ( x ) $ . The
slope of $ f _ \bot $ is $ - \frac { 1 } { m } $ and $ t _ \bot $ can be calculated:\nobreak
2013-11-05 20:30:34 +01:00
\begin { align}
f_ \bot (x) & = - \frac { 1} { m} \cdot x + t_ \bot \\
\Rightarrow y_ P & = - \frac { 1} { m} \cdot x_ P + t_ \bot \\
2013-11-22 21:40:15 +01:00
\Leftrightarrow t_ \bot & = y_ P + \frac { 1} { m} \cdot x_ P
\end { align}
2013-12-11 18:14:12 +01:00
The point $ ( x, f ( x ) ) $ where the perpendicular $ f _ \bot $ crosses $ f $
is calculated this way:
2013-11-22 21:40:15 +01:00
\begin { align}
2013-11-05 20:30:34 +01:00
f(x) & = f_ \bot (x)\\
\Leftrightarrow m \cdot x + t & = - \frac { 1} { m} \cdot x + \left (y_ P + \frac { 1} { m} \cdot x_ P \right )\\
\Leftrightarrow \left (m + \frac { 1} { m} \right ) \cdot x & = y_ P + \frac { 1} { m} \cdot x_ P - t\\
\Leftrightarrow x & = \frac { m} { m^ 2+1} \left ( y_ P + \frac { 1} { m} \cdot x_ P - t \right )
\end { align}
2013-11-22 21:40:15 +01:00
There is only one point with minimal distance. See Figure~\ref { fig:linear-min-distance} .
2013-11-05 20:47:41 +01:00
\clearpage
2013-11-22 21:40:15 +01:00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Quadratic functions %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2013-11-05 20:30:34 +01:00
\section { Minimal distance to a quadratic function}
Let $ f ( x ) = a \cdot x ^ 2 + b \cdot x + c $ with $ a \in \mdr \setminus \Set { 0 } $ and
2013-11-22 21:40:15 +01:00
$ b, c \in \mdr $ be a quadratic function.
2013-11-05 20:30:34 +01:00
\begin { figure} [htp]
\centering
\begin { tikzpicture}
\begin { axis} [
legend pos=north west,
axis x line=middle,
axis y line=middle,
grid = major,
width=0.8\linewidth ,
height=8cm,
grid style={ dashed, gray!30} ,
2013-12-11 18:14:12 +01:00
xmin=-3, % start the diagram at this x-coordinate
2013-11-05 20:30:34 +01:00
xmax= 3, % end the diagram at this x-coordinate
2013-12-11 18:14:12 +01:00
ymin=-0.25, % start the diagram at this y-coordinate
ymax= 9, % end the diagram at this y-coordinate
2013-11-05 20:30:34 +01:00
axis background/.style={ fill=white} ,
xlabel=$ x $ ,
ylabel=$ y $ ,
tick align=outside,
minor tick num=-3,
enlargelimits=true,
tension=0.08]
2013-12-11 18:14:12 +01:00
\addplot [domain=-3:3, thick,samples=50, red] { 0.5*x*x} ;
\addplot [domain=-3:3, thick,samples=50, green] { x*x} ;
\addplot [domain=-3:3, thick,samples=50, blue] { x*x + x} ;
\addplot [domain=-3:3, thick,samples=50, orange,dotted] { x*x + 2*x} ;
\addplot [domain=-3:3, thick,samples=50, black,dashed] { -x*x + 6} ;
2013-11-05 20:30:34 +01:00
\addlegendentry { $ f _ 1 ( x ) = \frac { 1 } { 2 } x ^ 2 $ }
\addlegendentry { $ f _ 2 ( x ) = x ^ 2 $ }
\addlegendentry { $ f _ 3 ( x ) = x ^ 2 + x $ }
\addlegendentry { $ f _ 4 ( x ) = x ^ 2 + 2 x $ }
\addlegendentry { $ f _ 5 ( x ) = - x ^ 2 + 6 $ }
\end { axis}
\end { tikzpicture}
\caption { Quadratic functions}
\end { figure}
2013-11-22 23:23:03 +01:00
\subsection { Calculate points with minimal distance}
2013-11-23 01:18:22 +01:00
In this case, $ d _ { P,f } ^ 2 $ is polynomial of degree 4.
We use Theorem~\ref { thm:required-extremum-property} :\nobreak
2013-11-22 23:23:03 +01:00
\begin { align}
2013-11-23 01:18:22 +01:00
0 & \overset { !} { =} (d_ { P,f} ^ 2)'\\
& = -2 x_ p + 2x -2y_ p f'(x) + \left (f(x)^ 2 \right )'\\
& = -2 x_ p + 2x -2y_ p f'(x) + 2 f(x) \cdot f'(x) \rlap { \hspace * { 3em} (chain rule)} \label { eq:minimizingFirstDerivative} \\
2013-11-25 08:13:14 +01:00
\Leftrightarrow 0 & \overset { !} { =} -x_ p + x -y_ p f'(x) + f(x) \cdot f'(x) \rlap { \hspace * { 3em} (divide by 2)} \label { eq:minimizingFirstDerivative} \\
& = -x_ p + x -y_ p (2ax+b) + (ax^ 2+bx+c)(2ax+b)\\
& = -x_ p + x -y_ p \cdot 2ax- y_ p b + (2 a^ 2 x^ 3+2 a b x^ 2+2 a c x+ab x^ 2+b^ 2 x+bc)\\
& = -x_ p + x -2y_ p ax- y_ p b + (2a^ 2 x^ 3 + 3 ab x^ 2 + 2acx + b^ 2 x + bc)\\
2013-12-05 23:27:17 +01:00
& = 2a^ 2 x^ 3 + 3 ab x^ 2 + (1 -2y_ p a+ 2ac + b^ 2)x +(bc-by_ p-x_ p)\label { eq:quadratic-derivative-eq-0}
2013-11-22 23:23:03 +01:00
\end { align}
This is an algebraic equation of degree 3.
2013-11-23 01:18:22 +01:00
There can be up to 3 solutions in such an equation. Those solutions
can be found with a closed formula.
2013-11-22 23:23:03 +01:00
2013-11-23 01:18:22 +01:00
\todo [inline] { Where are those closed formulas?}
2013-11-22 23:23:03 +01:00
2013-11-23 01:18:22 +01:00
\begin { example}
Let $ a = 1 , b = 0 , c = 1 , x _ p = 0 , y _ p = 1 $ .
So $ f ( x ) = x ^ 2 + 1 $ and $ P ( 0 , 1 ) $ .
2013-11-22 23:23:03 +01:00
\begin { align}
0 & \stackrel { !} { =} 4 x^ 3 - 2x\\
& =2x(2x^ 2 - 1)\\
\Rightarrow x_ 1 & = 0 \; \; \; x_ { 2,3} = \pm \frac { 1} { \sqrt { 2} }
\end { align}
As you can easily verify, only $ x _ 1 $ is a minimum of $ d _ { P,f } $ .
2013-11-23 01:18:22 +01:00
\end { example}
2013-11-22 23:23:03 +01:00
2013-11-05 20:30:34 +01:00
\subsection { Number of points with minimal distance}
2013-12-05 23:49:36 +01:00
\begin { theorem}
A point $ P $ has either one or two points on the graph of a
quadratic function $ f $ that are closest to $ P $ .
\end { theorem}
2013-11-23 01:18:22 +01:00
2013-12-05 23:49:36 +01:00
In the following, I will do some transformations with $ f = f _ 0 $ and
$ P = P _ 0 $ .
2013-11-05 20:30:34 +01:00
2013-12-05 23:49:36 +01:00
Moving $ f _ 0 $ and $ P _ 0 $ simultaneously in $ x $ or $ y $ direction does
not change the minimum distance. Furthermore, we can find the
points with minimum distance on the moved situation and calculate
the minimum points in the original situation.
2013-11-05 20:30:34 +01:00
2013-12-05 23:49:36 +01:00
First of all, we move $ f _ 0 $ and $ P _ 0 $ by $ \frac { b } { 2 a } $ in $ x $ direction, so
2013-12-05 23:27:17 +01:00
\[ f _ 1 ( x ) = ax ^ 2 - \frac { b ^ 2 } { 4 a } + c \; \; \; \text { and } \; \; \; P _ 1 = \left ( x _ p + \frac { b } { 2 a } , \; \; y _ p \right ) \]
2013-12-11 18:14:12 +01:00
Because:\footnote { The idea why you subtract $ \frac { b } { 2 a } $ within
$ f $ is that when you subtract something from $ x $ before applying
$ f $ it takes more time ($ x $ needs to be bigger) to get to the same
situation. So to move the whole graph by $ 1 $ to the left whe have
to add $ + 1 $ .}
2013-12-05 23:27:17 +01:00
\begin { align}
f(x-\nicefrac { b} { 2a} ) & = a (x-\nicefrac { b} { 2a} )^ 2 + b (x-\nicefrac { b} { 2a} ) + c\\
& = a (x^ 2 - \nicefrac { b} { a} x + \nicefrac { b^ 2} { 4a^ 2} ) + bx - \nicefrac { b^ 2} { 2a} + c\\
& = ax^ 2 - bx + \nicefrac { b^ 2} { 4a} + bx - \nicefrac { b^ 2} { 2a} + c\\
& = ax^ 2 -\nicefrac { b^ 2} { 4a} + c
\end { align}
Then move $ f _ 1 $ and $ P _ 1 $ by $ \frac { b ^ 2 } { 4 a } - c $ in $ y $ direction. You get:
2013-12-11 18:14:12 +01:00
\[ f _ 2 ( x ) = ax ^ 2 \; \; \; \text { and } \; \; \; P _ 2 = \Big ( \underbrace { x _ P + \frac { b } { 2 a } } _ { = : z } , \; \; \underbrace { y _ P + \frac { b ^ 2 } { 4 a } - c } _ { = : w } \Big ) \]
2013-12-05 23:27:17 +01:00
2013-12-06 12:20:49 +01:00
\textbf { Case 1:} As $ f _ 2 ( x ) = ax ^ 2 $ is symmetric to the $ y $ axis, only points
2013-12-05 23:49:36 +01:00
$ P = ( 0 , w ) $ could possilby have three minima.
2013-12-05 23:27:17 +01:00
Then compute:
\begin { align}
2013-12-11 18:14:12 +01:00
d_ { P,{ f_ 2} } (x) & = \sqrt { (x-0)^ 2 + (f_ 2(x)-w)^ 2} \\
2013-12-05 23:49:36 +01:00
& = \sqrt { x^ 2 + (ax^ 2-w)^ 2} \\
& = \sqrt { x^ 2 + a^ 2 x^ 4-2aw x^ 2+w^ 2} \\
& = \sqrt { a^ 2 x^ 4 + (1-2aw) x^ 2 + w^ 2} \\
& = \sqrt { \left (a^ 2 x^ 2 + \frac { 1-2 a w} { 2} \right )^ 2 + w^ 2 - (1-2 a w)^ 2} \\
2013-12-11 18:14:12 +01:00
& = \sqrt { \left (a^ 2 x^ 2 + \nicefrac { 1} { 2} -a w \right )^ 2 + \big (w^ 2 - (1-2 a w)^ 2 \big )}
2013-12-05 23:27:17 +01:00
\end { align}
2013-12-06 00:30:05 +01:00
The term
\[ a ^ 2 x ^ 2 + ( \nicefrac { 1 } { 2 } - a w ) \]
should get as close to $ 0 $ as possilbe when we want to minimize
$ d _ { P, { f _ 2 } } $ . For $ w \leq \nicefrac { 1 } { 2 a } $ you only have $ x = 0 $ as a minimum.
For all other points $ P = ( 0 , w ) $ , there are exactly two minima $ x _ { 1 , 2 } = \pm \sqrt { aw - \nicefrac { 1 } { 2 } } $ .
2013-12-05 23:49:36 +01:00
2013-12-06 12:20:49 +01:00
\textbf { Case 2:} $ P = ( z, w ) $ is not on the symmetry axis, so $ z \neq 0 $ . Then you compute:
\begin { align}
d_ { P,{ f_ 2} } (x) & = \sqrt { (x-z)^ 2 + (f(x)-w)^ 2} \\
2013-12-11 18:14:12 +01:00
& = \sqrt { (x^ 2 - 2zx + z^ 2) + ((ax^ 2)^ 2 - 2 awx^ 2 + w^ 2)} \\
& = \sqrt { a^ 2x^ 4 + (1- 2 aw)x^ 2 +(- 2z)x + z^ 2 + w^ 2} \\
0 & \stackrel { !} { =} \Big (\big (d_ { P, { f_ 2} } (x)\big )^ 2\Big )' \\
2013-12-06 12:20:49 +01:00
& = 4a^ 2x^ 3 + 2(1- 2 aw)x +(- 2z)\\
& = 2 \left (2a^ 2x^ 2 + (1- 2 aw) \right )x - 2z\\
2013-12-11 18:14:12 +01:00
\Leftrightarrow 0 & \stackrel { !} { =} (2a^ 2x^ 2 + (1- 2 aw)) x - z\\
& = 2 a^ 2 x^ 3 + (1- 2 aw) x - z\\
\Leftrightarrow 0 & \stackrel { !} { =} x^ 3 + \underbrace { \frac { (1- 2 aw)} { 2 a^ 2} } _ { =: \alpha } x + \underbrace { \frac { -z} { 2 a^ 2} } _ { =: \beta } \\
& = x^ 3 + \alpha x + \beta \label { eq:simple-cubic-equation-for-quadratic-distance}
2013-12-06 12:20:49 +01:00
\end { align}
2013-12-11 18:14:12 +01:00
The solution of Equation~\ref { eq:simple-cubic-equation-for-quadratic-distance}
is
2013-12-11 18:45:47 +01:00
\[ t : = \sqrt [ 3 ] { \sqrt { 3 \cdot ( 4 \alpha ^ 3 + 27 \beta ^ 2 ) } - 9 \beta } \]
\[ x = \frac { t } { \sqrt [ 3 ] { 18 } } - \frac { \sqrt [ 3 ] { \frac { 2 } { 3 } } \alpha } { t } \]
2013-12-06 12:20:49 +01:00
2013-12-11 18:45:47 +01:00
When you insert is in Equation~\ref { eq:simple-cubic-equation-for-quadratic-distance}
you get:
\begin { align}
0 & = \left (\frac { t} { \sqrt [3] { 18} } - \frac { \sqrt [3] { \frac { 2} { 3} } \alpha } { t} \right )^ 3 + \alpha \left (\frac { t} { \sqrt [3] { 18} } - \frac { \sqrt [3] { \frac { 2} { 3} } \alpha } { t} \right ) + \beta \\
& = (\frac { t} { \sqrt [3] { 18} } )^ 3 - 3 (\frac { t} { \sqrt [3] { 18} } )^ 2 \frac { \sqrt [3] { \frac { 2} { 3} } \alpha } { t} + 3 (\frac { t} { \sqrt [3] { 18} } )(\frac { \sqrt [3] { \frac { 2} { 3} } \alpha } { t} )^ 2 + (\frac { \sqrt [3] { \frac { 2} { 3} } \alpha } { t} )^ 3 + \alpha \left (\frac { t} { \sqrt [3] { 18} } - \frac { \sqrt [3] { \frac { 2} { 3} } \alpha } { t} \right ) + \beta \\
& = \frac { t^ 3} { 18} - \frac { 3t^ 2} { \sqrt [3] { 18^ 2} } \frac { \sqrt [3] { \frac { 2} { 3} } \alpha } { t} + \frac { 3t} { \sqrt [3] { 18} } \frac { \sqrt [3] { \frac { 4} { 9} } \alpha ^ 2 } { t^ 2} + \frac { \frac { 2} { 3} \alpha ^ 3 } { t^ 3} + \alpha \left (\frac { t} { \sqrt [3] { 18} } - \frac { \sqrt [3] { \frac { 2} { 3} } \alpha } { t} \right ) + \beta \\
& = \frac { t^ 3} { 18} - \frac { \sqrt [3] { 18} t \alpha } { \sqrt [3] { 18^ 2} } + \frac { \sqrt [3] { 12} \alpha ^ 2} { \sqrt [3] { 18} t} + \frac { \frac { 2} { 3} \alpha ^ 3 } { t^ 3} + \alpha \left (\frac { t} { \sqrt [3] { 18} } - \frac { \sqrt [3] { \frac { 2} { 3} } \alpha } { t} \right ) + \beta \\
& = \frac { t^ 3} { 18} - \frac { t \alpha } { \sqrt [3] { 18} } + \frac { \sqrt [3] { 2} \alpha ^ 2} { \sqrt [3] { 3} t} + \frac { \frac { 2} { 3} \alpha ^ 3 } { t^ 3} + \alpha \left (\frac { t} { \sqrt [3] { 18} } - \frac { \sqrt [3] { \frac { 2} { 3} } \alpha } { t} \right ) + \beta \\
& = \frac { t^ 3} { 18} - \frac { t \alpha } { \sqrt [3] { 18} } + \frac { \frac { 2} { 3} \alpha ^ 3 } { t^ 3} + \frac { \alpha t} { \sqrt [3] { 18} } + \beta \\
& = \frac { t^ 3} { 18} + \frac { \frac { 2} { 3} \alpha ^ 3 } { t^ 3} + \beta \\
\end { align}
2013-12-11 18:14:12 +01:00
\todo [inline] { verify this solution}
2013-12-05 23:49:36 +01:00
2013-12-06 12:20:49 +01:00
\goodbreak
So the solution is given by
2013-12-06 00:30:05 +01:00
\begin { align*}
2013-12-06 00:37:04 +01:00
x_ S & := - \frac { b} { 2a} \; \; \; \; \; \text { (the symmetry axis)} \\
2013-12-06 00:30:05 +01:00
\underset { x\in \mdr } { \arg \min d_ { P,f} (x)} & = \begin { cases}
x_ 1 = +\sqrt { a (y_ p + \frac { b^ 2} { 4a} - c) - \frac { 1} { 2} } + x_ S \text { and } & \text { if } x_ P = x_ S \text { and } y_ p + \frac { b^ 2} { 4a} - c > \frac { 1} { 2a} \\
x_ 2 = -\sqrt { a (y_ p + \frac { b^ 2} { 4a} - c) - \frac { 1} { 2} } + x_ S\\
x_ 1 = x_ S & \text { if } x_ P = x_ S \text { and } y_ p + \frac { b^ 2} { 4a} - c \leq \frac { 1} { 2a} \\
x_ 1 = todo & \text { if } x_ P \neq x_ S
\end { cases}
\end { align*}
2013-12-05 23:27:17 +01:00
2013-11-23 01:18:22 +01:00
\clearpage
2013-11-22 21:40:15 +01:00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Cubic %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2013-11-05 20:30:34 +01:00
\section { Minimal distance to a cubic function}
2013-11-22 21:40:15 +01:00
Let $ f ( x ) = a \cdot x ^ 3 + b \cdot x ^ 2 + c \cdot x + d $ be a cubic function
with $ a \in \mdr \setminus \Set { 0 } $ and
2013-11-05 20:47:41 +01:00
$ b, c, d \in \mdr $ be a function.
2013-11-23 01:18:22 +01:00
\begin { figure} [htp]
\centering
\begin { tikzpicture}
\begin { axis} [
legend pos=south east,
axis x line=middle,
axis y line=middle,
grid = major,
width=0.8\linewidth ,
height=8cm,
grid style={ dashed, gray!30} ,
2013-12-11 18:14:12 +01:00
xmin=-3, % start the diagram at this x-coordinate
xmax= 3, % end the diagram at this x-coordinate
ymin=-3, % start the diagram at this y-coordinate
ymax= 3, % end the diagram at this y-coordinate
2013-11-23 01:18:22 +01:00
axis background/.style={ fill=white} ,
xlabel=$ x $ ,
ylabel=$ y $ ,
tick align=outside,
minor tick num=-3,
enlargelimits=true,
tension=0.08]
\addplot [domain=-3:3, thick,samples=50, red] { x*x*x} ;
\addplot [domain=-3:3, thick,samples=50, green] { x*x*x+x*x} ;
\addplot [domain=-3:3, thick,samples=50, blue] { x*x*x+2*x*x} ;
\addplot [domain=-3:3, thick,samples=50, orange] { x*x*x+x} ;
\addlegendentry { $ f _ 1 ( x ) = x ^ 3 $ }
\addlegendentry { $ f _ 2 ( x ) = x ^ 3 + x ^ 2 $ }
\addlegendentry { $ f _ 2 ( x ) = x ^ 3 + 2 \cdot x ^ 2 $ }
\addlegendentry { $ f _ 1 ( x ) = x ^ 3 + x $ }
\end { axis}
\end { tikzpicture}
\caption { Cubic functions}
\end { figure}
2013-11-05 20:47:41 +01:00
2013-11-23 01:18:22 +01:00
%
%\subsection{Special points}
%\todo[inline]{Write this}
%
%\subsection{Voronoi}
%
%For $b^2 \geq 3ac$
%
%\todo[inline]{Write this}
2013-11-05 20:47:41 +01:00
2013-11-05 20:30:34 +01:00
\subsection { Calculate points with minimal distance}
2013-12-11 18:14:12 +01:00
\begin { theorem}
There cannot be an algebraic solution to the problem of finding
a closest point $ ( x, f ( x ) ) $ to a given point $ P $ when $ f $ is
a polynomial function of degree $ 3 $ or higher.
\end { theorem}
\begin { proof}
2013-12-11 18:24:52 +01:00
Suppose you could solve the closest point problem for arbitrary
cubic functions $ f = ax ^ 3 + bx ^ 2 + cx + d $ and arbitrary points $ P = ( x _ P, y _ P ) $ .
Then you could solve the following problem for $ x $ :
\begin { align}
0 & \stackrel { !} { =} \left ((d_ { P,f} (x))^ 2 \right )'
& =-2 x_ p + 2x -2y_ p(f(x))' + (f(x)^ 2)'\\
& = 2 f(x) \cdot f'(x) - 2 y_ p f'(x) + 2x - 2 x_ p\\
& = f(x) \cdot f'(x) - y_ p f'(x) + x - x_ p\\
& = \underbrace { f'(x) \cdot \left (f(x) - y_ p \right )} _ { \text { Polynomial of degree 5} } + x - x_ p
\end { align}
General algebraic equations of degree 5 don't have a solution formula.\footnote { TODO: Quelle}
Although here seems to be more structure, the resulting algebraic
equation can be almost any polynomial of degree 5:\footnote { Thanks to Peter Košinár on \href { http://math.stackexchange.com/a/584814/6876} { math.stackexchange.com} for this one}
\begin { align}
0 & \stackrel { !} { =} f'(x) \cdot \left (f(x) - y_ p \right ) + (x - x_ p)\\
& = \underbrace { 3 a^ 2} _ { = \tilde { a} } x^ 5 + \underbrace { 5ab} _ { \tilde { b} } x^ 4 + \underbrace { 2(2ac + b^ 2 )} _ { =: \tilde { c} } x^ 3 & +& \underbrace { 3(ad+bc-ay_ p)} _ { \tilde { d} } x^ 2 \\
& & +& \underbrace { (2 b d+c^ 2+1-2 b y_ p)} _ { =: \tilde { e} } x+\underbrace { c d-c y_ p-x_ p} _ { =: \tilde { f} } \\
0 & \stackrel { !} { =} \tilde { a} x^ 5 + \tilde { b} x^ 4 + \tilde { c} x^ 3 + \tilde { d} x^ 2 + \tilde { e} x + \tilde { f}
\end { align}
\begin { enumerate}
\item For any coefficient $ \tilde { a } \in \mdr _ { > 0 } $ of $ x ^ 5 $ we can choose $ a $ such that we get $ \tilde { a } $ .
\item For any coefficient $ \tilde { b } \in \mdr \setminus \Set { 0 } $ of $ x ^ 4 $ we can choose $ b $ such that we get $ \tilde { b } $ .
\item With $ c $ , we can get any value of $ \tilde { c } \in \mdr $ .
\item With $ d $ , we can get any value of $ \tilde { d } \in \mdr $ .
\item With $ y _ p $ , we can get any value of $ \tilde { e } \in \mdr $ .
\item With $ x _ p $ , we can get any value of $ \tilde { f } \in \mdr $ .
\end { enumerate}
The first restriction guaratees that we have a polynomial of
degree 5. The second one is necessary, to get a high range of
$ \tilde { e } $ .
This means, that there is no solution formula for the problem of
finding the closest points on a cubic function to a given point,
because if there was one, you could use this formula for finding
roots of polynomials of degree 5. $ \qed $
2013-12-11 18:14:12 +01:00
\end { proof}
2013-11-23 01:23:27 +01:00
2013-12-06 12:20:49 +01:00
\subsection { Another approach}
Just like we moved the function $ f $ and the point to get in a
nicer situation, we can apply this approach for cubic functions.
\begin { figure} [htp]
\centering
\begin { tikzpicture}
\begin { axis} [
legend pos=south east,
axis x line=middle,
axis y line=middle,
grid = major,
width=0.8\linewidth ,
height=8cm,
grid style={ dashed, gray!30} ,
2013-12-11 18:14:12 +01:00
xmin=-3, % start the diagram at this x-coordinate
xmax= 3, % end the diagram at this x-coordinate
ymin=-3, % start the diagram at this y-coordinate
ymax= 3, % end the diagram at this y-coordinate
2013-12-06 12:20:49 +01:00
axis background/.style={ fill=white} ,
xlabel=$ x $ ,
ylabel=$ y $ ,
tick align=outside,
minor tick num=-3,
enlargelimits=true,
tension=0.08]
\addplot [domain=-3:3, thick,samples=50, red] { x*x*x} ;
\addplot [domain=-3:3, thick,samples=50, green] { x*x*x+x} ;
\addplot [domain=-3:3, thick,samples=50, orange] { x*x*x-x} ;
\addplot [domain=-3:3, thick,samples=50, blue, dotted] { x*x*x+2*x} ;
\addplot [domain=-3:3, thick,samples=50, lime, dashed] { x*x*x+3*x} ;
\addlegendentry { $ f _ 1 ( x ) = x ^ 3 $ }
\addlegendentry { $ f _ 2 ( x ) = x ^ 3 + x $ }
\addlegendentry { $ f _ 1 ( x ) = x ^ 3 - x $ }
\addlegendentry { $ f _ 2 ( x ) = x ^ 3 + 2 \cdot x $ }
\addlegendentry { $ f _ 2 ( x ) = x ^ 3 + 3 \cdot x $ }
\end { axis}
\end { tikzpicture}
\caption { Cubic functions with $ b = d = 0 $ }
\end { figure}
First, we move $ f _ 0 $ by $ \frac { b } { 3 a } $ to the right, so
\[ f _ 1 ( x ) = ax ^ 3 + \frac { b ^ 2 ( c - 1 ) } { 3 a } x + \frac { 2 b ^ 3 } { 27 a ^ 2 } - \frac { bc } { 3 a } + d \; \; \; \text { and } \; \; \; P _ 1 = ( x _ P + \frac { b } { 3 a } , y _ P ) \]
because
\begin { align}
f_ 1(x) & = a \left (x - \frac { b} { 3a} \right )^ 3 + b \left (x-\frac { b} { 3a} \right )^ 2 + c \left (x-\frac { b} { 3a} \right ) + d\\
& = a \left (x^ 3 - 3 \frac { b} { 3a} x^ 2 + 3 (\frac { b} { 3a} )^ 2 x - \frac { b^ 3} { 27a^ 3} \right )
+b \left (x^ 2 - \frac { 2b} { 3a} x + \frac { b^ 2} { 9a^ 2} \right )
+c x - \frac { bc} { 3a} + d\\
& = ax^ 3 - bx^ 2 + \frac { b^ 2} { 3a} x - \frac { b^ 3} { 27 a^ 2} \\
& \; \; \; \; \; \; + bx^ 2 - \frac { 2b^ 2} { 3a} x + \frac { b^ 3} { 9a^ 2} \\
& \; \; \; \; \; \; \; \; \; \; \; \; + c x - \frac { bc} { 3a} + d\\
& = ax^ 3 + \frac { b^ 2} { 3a} \left (1-2+c \right )x + \frac { b^ 3} { 9a^ 2} \left (1-\frac { 1} { 3} \right )- \frac { bc} { 3a} + d
\end { align}
\todo [inline] { Which way to move might be clever?}
2013-11-23 01:18:22 +01:00
\subsection { Number of points with minimal distance}
As there is an algebraic equation of degree 5, there cannot be more
than 5 solutions.
\todo [inline] { Can there be 3, 4 or even 5 solutions? Examples!
2013-11-22 21:40:15 +01:00
2013-11-23 01:18:22 +01:00
After looking at function graphs of cubic functions, I'm pretty
sure that there cannot be 4 or 5 solutions, no matter how you
chose the cubic function $ f $ and $ P $ .
2013-11-22 21:40:15 +01:00
2013-11-23 01:18:22 +01:00
I'm also pretty sure that there is no polynomial (no matter what degree)
that has more than 3 solutions.}
2013-11-23 01:26:03 +01:00
2013-12-11 18:14:12 +01:00
\section { Newtons method}
\todo [inline] { When does Newtons method converge? How fast?
How to choose starting point?}
\section { Quadratic minimization}
\todo [inline] { TODO}
\section { Conclusion}
\todo [inline] { TODO}
2013-11-05 20:30:34 +01:00
\end { document}