2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-19 11:38:05 +02:00

Problem with quadratic solution - couldn't find it today

This commit is contained in:
Martin Thoma 2013-12-13 23:35:07 +01:00
parent f241ed6bf5
commit 76ec8c9cab
3 changed files with 34 additions and 13 deletions

View file

@ -136,12 +136,13 @@ For all other points $P = (0, w)$, there are exactly two minima $x_{1,2} = \pm \
&= 2 \left (2a^2x^2 + (1- 2 aw) \right )x - 2z\\
\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}\\
\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}
\end{align}
The solution of Equation~\ref{eq:simple-cubic-equation-for-quadratic-distance}
is
\todo[inline]{Can $4 \alpha^3 + 27 \beta^2$ be negative for $\alpha=\frac{1-2aw}{2a^2}$ and $\beta = \frac{-z}{2a^2}$?}
\[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}\]
@ -191,10 +192,12 @@ $t$:
\goodbreak
So the solution is given by
\todo[inline]{NO! Currently, there are erros in the solution.
Check $f(x) = x^2$ and $P=(-2,4)$. Solution should be $x_1 = -2$, but it isn't!}
\begin{align*}
x_S &:= - \frac{b}{2a} \;\;\;\;\; \text{(the symmetry axis)}\\
w &:= y_P+\frac{b^2}{4a}-c \;\;\; \text{ and } \;\;\; z := x_P+\frac{b}{2a}\\
\alpha &:= \frac{(1- 2 aw)}{2 a^2} \;\;\;\text{ and }\;\;\; \beta := \frac{-z}{2 a^2}\\
\alpha &:= \frac{1- 2 aw}{2 a^2} \;\;\;\text{ and }\;\;\; \beta := \frac{-z}{2 a^2}\\
t &:= \sqrt[3]{\sqrt{3 \cdot (4 \alpha^3 + 27 \beta^2)} -9\beta}\\
\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} \\

View file

@ -168,19 +168,37 @@ function findMin(p) {
var b = parseFloat(document.getElementById("b").value);
var c1 = parseFloat(document.getElementById("c").value);
var currentMinX = p.x;
for (var i=0; i < 10; i++) {
// Funktionswert
var fx = -2.0*p.x+2.0*currentMinX-2.0*p.y*getDValue(currentMinX) +gedSquaredValueD(currentMinX);
var fxd = 2.0 -2.0*p.y*getDDValue(currentMinX)+gedSquaredValueDD(currentMinX);
if (Math.abs(fxd) < 0.0001) {
return currentMinX;
}
/* old iterative solution that had problems near the center*/
var lastx = -10000;
var x = p.x;
var i = 0;
while (Math.abs(lastx-x) > 1 && i < 100) {
// first derivate of the square of the distance function
var fx = -2.0*p.x+2.0*x-2.0*p.y*getDValue(x) +2*getValue(x)*getDValue(x);
var fxd = 2.0 -2.0*p.y*getDDValue(x)+2*(getDValue(x)*getDValue(x) + getValue(x)*getDDValue(x));
if (fxd == 0) {
console.log("wow!");
return x;
}
// x_{n+1} = x_n - f(x_n)/f'(x_n) wenn x gesucht, sodass f(x) = 0 gilt
currentMinX -= fx / fxd;
lastx = x;
x -= fx / fxd;
i++;
}
return currentMinX;
// New direct solution
/*var xs = -b / (2*a);
var w = p.y + b*b/(4*a)-c1;
var z = p.x + b / (2*a);
var alpha = (1-2*a*w)/(2*a*a);
var beta = -z/(2*a*a);
var t = Math.pow(Math.pow(3*(4*Math.pow(alpha,3) +27* Math.pow(beta,2)),1/2) - 9*beta, 1/3);
var currentMinX = t / (Math.pow(18, 1/3)) - Math.pow(2/3*alpha, 1/3) / t;
*/
return x;
}
function getDist(p, minX) {
@ -244,7 +262,7 @@ canvas.addEventListener('mousemove',
var x = r(mouseCoords.x, true).toFixed(3);
var y = r(mouseCoords.y, false).toFixed(3);
context.fillText("(" + x + ", " + y + ")", mouseCoords.x + 5, mouseCoords.y - 5);
var minX = findMin({"x":x, "y":y});
var minX = findMin({"x": mouseCoords.x, "y": mouseCoords.y});
var minY = getValue(minX);
context.beginPath();
context.moveTo(c(minX, true), c(minY, false), false);