In mathematica I set f[x_] := Sign[x] Sqrt[Abs[x]]
and then I solved it in a root finding for Newton's method by doing FindRoot[f[x], {x, 1}, Method -> "Newton"]
which returns {x -> 0.}
. This is all fine and good as yes the root is obviously at f[0]
; however, when iterating newton's method for $f(x)=\text{Sign}(x)\sqrt{|x|}$ for the initial value $x_0 = 1$ you get $x_{k+1} = x_{k} - \frac{f(x_k)}{f'(x_k)}$ which turns into $x_{k+1} = x_k-2\text{Sign}(x)|x|$. We would get $x_1 = 1 - 2*\text{Sign}(1)*|1| = -1$ then we get $x_2 = -1 - 2*\text{Sign}(-1) |-1| = -1 + 2 = 1$ and it obviously oscillates at $\pm 1$ but never converges to zero; yet mathematica converges this to 0 immediately, is there a way to truly iterate newton's method in Mathematica?
Note that neither Sign
nor Abs
is differentiable so that Newton's Method may not be applied to the OP's problem in its given form.
Caveat:
I am assuming this is a toy example, to show that the unadorned Newton's method fails on some functions. Normally, FindRoot
uses step control to try to avoid certain common traps in using Newton's Method. One can turn off the protections with the option setting "StepControl" -> None
as shown below.
Needs["Optimization`UnconstrainedProblems`"]
FindRootPlot[Sign[x] Sqrt[Abs[x]], {x, 1},
Method -> {"Newton", "StepControl" -> None}]
If we define the functions in terms of differentiable functions, one can invoke Newton's Method successfully:
sign[x_] := Piecewise[{{1, x > 0}, {-1, x < 0}}, 0];
abs[x_] := Sqrt[x^2];
FindRootPlot[sign[x] Sqrt[abs[x]], {x, 1},
Method -> {"Newton", "StepControl" -> None}]
To see the steps, we can Sow
and Reap
them:
Reap@FindRoot[sign[x] Sqrt[abs[x]], {x, 1},
Method -> {"Newton", "StepControl" -> None}, StepMonitor :> Sow[x]]
The steps oscillate between ±1
.
-
$\begingroup$ Please replace
sign[x] Sqrt[abs[x]]
with uppercase letters. $\endgroup$ – user31001 Oct 3 '15 at 9:00 -
$\begingroup$ @Willinski. Michael is defining special versions of those functions to make his point. The replacement you request would invalidate his answer. $\endgroup$ – m_goldberg Oct 3 '15 at 9:41
-
$\begingroup$ @m_goldberg Oh, yes! My blind eyes! $\endgroup$ – user31001 Oct 3 '15 at 10:10
Method -> "Newton"
is not strictly pure newton but has some tweak to avoid such oscillation. What exactly is the question though? You can implement it yourself obviously. $\endgroup$ – george2079 Oct 2 '15 at 21:00Abs
andSign
so it will take bit of work to show your exact oscillation result. $\endgroup$ – george2079 Oct 2 '15 at 21:42