math-minimal-distance-to-cubic-function.tex 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. \documentclass[a4paper]{scrartcl}
  2. \usepackage{amssymb, amsmath} % needed for math
  3. \usepackage{mathtools} % \xRightarrow
  4. \usepackage[utf8]{inputenc} % this is needed for umlauts
  5. \usepackage[english]{babel} % this is needed for umlauts
  6. \usepackage[T1]{fontenc} % this is needed for correct output of umlauts in pdf
  7. \usepackage[margin=2.5cm]{geometry} %layout
  8. \usepackage{hyperref} % links im text
  9. \usepackage{braket} % needed for \Set
  10. \usepackage{parskip}
  11. \usepackage[colorinlistoftodos]{todonotes}
  12. \usepackage{pgfplots}
  13. \pgfplotsset{compat=1.7,compat/path replacement=1.5.1}
  14. \usepackage{tikz}
  15. \title{Minimal distance to a cubic function}
  16. \author{Martin Thoma}
  17. \hypersetup{
  18. pdfauthor = {Martin Thoma},
  19. pdfkeywords = {},
  20. pdftitle = {Minimal Distance}
  21. }
  22. \def\mdr{\ensuremath{\mathbb{R}}}
  23. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  24. % Begin document %
  25. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  26. \begin{document}
  27. \maketitle
  28. \begin{abstract}
  29. In this paper I want to discuss how to find all points on a a cubic
  30. function with minimal distance to a given point.
  31. \end{abstract}
  32. \section{Description of the Problem}
  33. Let $f: \mdr \rightarrow \mdr$ be a polynomial function and $P \in \mdr^2$
  34. be a point. Let $d: \mdr^2 \times \mdr^2 \rightarrow \mdr_0^+$
  35. be the euklidean distance of two points:
  36. \[d \left ((x_1, y_1), (x_2, y_2) \right) := \sqrt{(x_1 - x_2)^2 + (y_1 - y_2)^2}\]
  37. Now there is finite set of points $x_1, \dots, x_n$ such that
  38. \[\forall \tilde x \in \mathbb{R} \setminus \{x_1, \dots, x_n\}: d(P, (x_1, f(x_1))) = \dots = d(P, (x_n, f(x_n))) < d(P, (\tilde x, f(\tilde x)))\]
  39. \section{Minimal distance to a constant function}
  40. Let $f(x) = c$ with $c \in \mdr$ be a function.
  41. \begin{figure}[htp]
  42. \centering
  43. \begin{tikzpicture}
  44. \begin{axis}[
  45. legend pos=north west,
  46. axis x line=middle,
  47. axis y line=middle,
  48. grid = major,
  49. width=0.8\linewidth,
  50. height=8cm,
  51. grid style={dashed, gray!30},
  52. xmin=-5, % start the diagram at this x-coordinate
  53. xmax= 5, % end the diagram at this x-coordinate
  54. ymin= 0, % start the diagram at this y-coordinate
  55. ymax= 3, % end the diagram at this y-coordinate
  56. axis background/.style={fill=white},
  57. xlabel=$x$,
  58. ylabel=$y$,
  59. tick align=outside,
  60. minor tick num=-3,
  61. enlargelimits=true,
  62. tension=0.08]
  63. \addplot[domain=-5:5, thick,samples=50, red] {1};
  64. \addplot[domain=-5:5, thick,samples=50, green] {2};
  65. \addplot[domain=-5:5, thick,samples=50, blue] {3};
  66. \addplot[black, mark = *, nodes near coords=$P$,every node near coord/.style={anchor=225}] coordinates {(2, 2)};
  67. \draw[thick, dashed] (axis cs:2,0) -- (axis cs:2,3);
  68. \addlegendentry{$f(x)=1$}
  69. \addlegendentry{$g(x)=2$}
  70. \addlegendentry{$h(x)=3$}
  71. \end{axis}
  72. \end{tikzpicture}
  73. \caption{3 constant functions}
  74. \end{figure}
  75. Then $(x_P,f(x_P))$ has
  76. minimal distance to $P$. Every other point has higher distance.
  77. \section{Minimal distance to a linear function}
  78. Let $f(x) = m \cdot x + t$ with $m \in \mdr \setminus \Set{0}$ and
  79. $t \in \mdr$ be a function.
  80. \begin{figure}[htp]
  81. \centering
  82. \begin{tikzpicture}
  83. \begin{axis}[
  84. legend pos=north east,
  85. axis x line=middle,
  86. axis y line=middle,
  87. grid = major,
  88. width=0.8\linewidth,
  89. height=8cm,
  90. grid style={dashed, gray!30},
  91. xmin= 0, % start the diagram at this x-coordinate
  92. xmax= 5, % end the diagram at this x-coordinate
  93. ymin= 0, % start the diagram at this y-coordinate
  94. ymax= 3, % end the diagram at this y-coordinate
  95. axis background/.style={fill=white},
  96. xlabel=$x$,
  97. ylabel=$y$,
  98. tick align=outside,
  99. minor tick num=-3,
  100. enlargelimits=true,
  101. tension=0.08]
  102. \addplot[domain=-5:5, thick,samples=50, red] {0.5*x};
  103. \addplot[domain=-5:5, thick,samples=50, blue] {-2*x+6};
  104. \addplot[black, mark = *, nodes near coords=$P$,every node near coord/.style={anchor=225}] coordinates {(2, 2)};
  105. \addlegendentry{$f(x)=\frac{1}{2}x$}
  106. \addlegendentry{$g(x)=-2x+6$}
  107. \end{axis}
  108. \end{tikzpicture}
  109. \caption{The shortest distance of $P$ to $f$ can be calculated by using the perpendicular}
  110. \end{figure}
  111. Now you can drop a perpendicular through $P$ on $f(x)$. The slope $f_\bot$
  112. of the perpendicular is $- \frac{1}{m}$. Then:
  113. \begin{align}
  114. f_\bot(x) &= - \frac{1}{m} \cdot x + t_\bot\\
  115. \Rightarrow y_P &= - \frac{1}{m} \cdot x_P + t_\bot\\
  116. \Leftrightarrow t_\bot &= y_P + \frac{1}{m} \cdot x_P\\
  117. f(x) &= f_\bot(x)\\
  118. \Leftrightarrow m \cdot x + t &= - \frac{1}{m} \cdot x + \left(y_P + \frac{1}{m} \cdot x_P \right)\\
  119. \Leftrightarrow \left (m + \frac{1}{m} \right ) \cdot x &= y_P + \frac{1}{m} \cdot x_P - t\\
  120. \Leftrightarrow x &= \frac{m}{m^2+1} \left ( y_P + \frac{1}{m} \cdot x_P - t \right )
  121. \end{align}
  122. There is only one point with minimal distance.
  123. \clearpage
  124. \section{Minimal distance to a quadratic function}
  125. Let $f(x) = a \cdot x^2 + b \cdot x + c$ with $a \in \mdr \setminus \Set{0}$ and
  126. $b, c \in \mdr$ be a function.
  127. \begin{figure}[htp]
  128. \centering
  129. \begin{tikzpicture}
  130. \begin{axis}[
  131. legend pos=north west,
  132. axis x line=middle,
  133. axis y line=middle,
  134. grid = major,
  135. width=0.8\linewidth,
  136. height=8cm,
  137. grid style={dashed, gray!30},
  138. xmin=-3, % start the diagram at this x-coordinate
  139. xmax= 3, % end the diagram at this x-coordinate
  140. ymin=-0.25, % start the diagram at this y-coordinate
  141. ymax= 9, % end the diagram at this y-coordinate
  142. axis background/.style={fill=white},
  143. xlabel=$x$,
  144. ylabel=$y$,
  145. %xticklabels={-2,-1.6,...,7},
  146. %yticklabels={-8,-7,...,8},
  147. tick align=outside,
  148. minor tick num=-3,
  149. enlargelimits=true,
  150. tension=0.08]
  151. \addplot[domain=-3:3, thick,samples=50, red] {0.5*x*x};
  152. \addplot[domain=-3:3, thick,samples=50, green] {x*x};
  153. \addplot[domain=-3:3, thick,samples=50, blue] {x*x + x};
  154. \addplot[domain=-3:3, thick,samples=50, orange] {x*x + 2*x};
  155. \addplot[domain=-3:3, thick,samples=50, black] {-x*x + 6};
  156. \addlegendentry{$f_1(x)=\frac{1}{2}x^2$}
  157. \addlegendentry{$f_2(x)=x^2$}
  158. \addlegendentry{$f_3(x)=x^2+x$}
  159. \addlegendentry{$f_4(x)=x^2+2x$}
  160. \addlegendentry{$f_5(x)=-x^2+6$}
  161. \end{axis}
  162. \end{tikzpicture}
  163. \caption{Quadratic functions}
  164. \end{figure}
  165. \subsection{Number of points with minimal distance}
  166. It is obvious that a quadratic function can have two points with
  167. minimal distance.
  168. For example, let $f(x) = x^2$ and $P = (0,5)$. Then $P_{f,1} \approx (2.179, 2.179^2)$
  169. has minimal distance to $P$, but also $P_{f,2}\approx (-2.179, 2.179^2)$.
  170. Obviously, there cannot be more than three points with minimal distance.
  171. But can there be three points?
  172. \begin{figure}[htp]
  173. \centering
  174. \begin{tikzpicture}
  175. \begin{axis}[
  176. legend pos=north west,
  177. axis x line=middle,
  178. axis y line=middle,
  179. grid = major,
  180. width=0.8\linewidth,
  181. height=8cm,
  182. grid style={dashed, gray!30},
  183. xmin=-0.7, % start the diagram at this x-coordinate
  184. xmax= 0.7, % end the diagram at this x-coordinate
  185. ymin=-0.25, % start the diagram at this y-coordinate
  186. ymax= 0.5, % end the diagram at this y-coordinate
  187. axis background/.style={fill=white},
  188. xlabel=$x$,
  189. ylabel=$y$,
  190. %xticklabels={-2,-1.6,...,7},
  191. %yticklabels={-8,-7,...,8},
  192. tick align=outside,
  193. minor tick num=-3,
  194. enlargelimits=true,
  195. tension=0.08]
  196. \addplot[domain=-0.7:0.7, thick,samples=50, orange] {x*x};
  197. \draw (axis cs:0,0.5) circle[radius=0.5];
  198. \draw[red, thick] (axis cs:0,0.5) -- (axis cs:0.101,0.0102);
  199. \draw[red, thick] (axis cs:0,0.5) -- (axis cs:-0.101,0.0102);
  200. \draw[red, thick] (axis cs:0,0.5) -- (axis cs:0,0);
  201. \addlegendentry{$f(x)=x^2$}
  202. \end{axis}
  203. \end{tikzpicture}
  204. \caption{3 points with minimal distance?}
  205. \todo[inline]{Is this possible? http://math.stackexchange.com/q/553097/6876}
  206. \end{figure}
  207. As the point is already given, you want to minimize the following
  208. function:
  209. \begin{align}
  210. d: &\mdr \rightarrow \mdr^+_0\\
  211. d(x) &= \sqrt{(x_p,y_p),(x,f(x))}\\
  212. &= \sqrt{(x_p-x)^2 + (y_p - f(x))^2}\\
  213. &= \sqrt{x_p^2 - 2x_p x + x^2 + y_p^2 - 2y_p f(x) + f(x)^2}
  214. \end{align}
  215. Minimizing $d$ is the same as minimizing $d^2$:
  216. \begin{align}
  217. d(x)^2 &= x_p^2 - 2x_p x + x^2 + y_p^2 - 2y_p f(x) + f(x)^2\\
  218. (d(x)^2)' &= -2 x_p + 2x -2y_p(f(x))' + (f(x)^2)'\\
  219. 0 &\stackrel{!}{=} -2 x_p + 2x -2y_p(f(x))' + (f(x)^2)'
  220. \end{align}
  221. Now we use thet $f(x) = ax^2 + bx + c$:
  222. \begin{align}
  223. 0 &\stackrel{!}{=} -2 x_p + 2x -2y_p(2ax+b) + ((ax^2+bx+c)^2)'\\
  224. &= -2 x_p + 2x -2y_p \cdot 2ax-2 y_p b + (a^2 x^4+2 a b x^3+2 a c x^2+b^2 x^2+2 b c x+c^2)'\\
  225. &= -2 x_p + 2x -4y_p ax-2 y_p b + (4a^2 x^3 + 6 ab x^2 + 4acx + 2b^2 x + 2bc)\\
  226. &= 4a^2 x^3 + 6 ab x^2 + 2(1 -2y_p a+ 2ac + b^2)x +2(bc-by_p-x_p)\\
  227. \end{align}
  228. \subsubsection{Solutions}
  229. As the problem stated above is a cubic equation, you can solved it
  230. analytically. But the solutions are not very nice, so I've entered
  231. \texttt{$0=4*a^2 *x^3 + 6 *a*b *x^2 + 2*(1 -2*e *a+ 2*a*c + b^2)*x +2*(b*c-b*e-d)$}
  232. with $d := x_p$ and $e := y_p$.
  233. to \href{http://www.wolframalpha.com/input/?i=0%3D4*a%5E2+*x%5E3+%2B+6+*a*b+*x%5E2+%2B+2*%281+-2*e+*a%2B+2*a*c+%2B+b%5E2%29*x+%2B2*%28b*c-b*e-d%29}{WolframAlpha} to let it solve. The solutions are:
  234. \textbf{First solution}
  235. \begin{align*}
  236. x = &\frac{1}{6 \sqrt[3]{2} a^2} \sqrt[3]{(108 a^4 d+54 a^3 b+\sqrt{(108 a^4 d+54 a^3 b)^2+4 (12 a^3 c-12 a^3 e-3 a^2 b^2+6 a^2)^3})}\\
  237. &-\frac{12 a^3 c-12 a^3 e-3 a^2 b^2+6 a^2}
  238. {3 (2^{\frac{2}{3}}) a^2 \sqrt[3]{108 a^4 d+54 a^3 b+\sqrt{(108 a^4 d+54 a^3 b)^2+4 (12 a^3 c-12 a^3 e-3 a^2 b^2+6 a^2)^3}} }-b/(2 a)
  239. \end{align*}
  240. So the minimum for $a=1, b=c=d=0$ is:
  241. \subsection{Calculate points with minimal distance}
  242. \todo[inline]{Write this}
  243. \section{Minimal distance to a cubic function}
  244. Let $f(x) = a \cdot x^3 + b \cdot x^2 + c \cdot x + d$ with $a \in \mdr \setminus \Set{0}$ and
  245. $b, c, d \in \mdr$ be a function.
  246. \subsection{Number of points with minimal distance}
  247. \todo[inline]{Write this}
  248. \subsection{Special points}
  249. \todo[inline]{Write this}
  250. \subsection{Voronoi}
  251. For $b^2 \geq 3ac$
  252. \todo[inline]{Write this}
  253. \subsection{Calculate points with minimal distance}
  254. \todo[inline]{Write this}
  255. \end{document}