Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #6689 > unrolled thread
| Started by | HwB <hwborchers@googlemail.com> |
|---|---|
| First post | 2011-11-24 12:04 +0000 |
| Last post | 2011-12-06 03:06 +0000 |
| Articles | 8 — 5 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Root finding needs higher accuracy HwB <hwborchers@googlemail.com> - 2011-11-24 12:04 +0000
Re: Root finding needs higher accuracy "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-11-25 09:55 +0000
Re: Root finding needs higher accuracy Peter Falloon <pfalloon@gmail.com> - 2011-11-25 10:04 +0000
Re: Root finding needs higher accuracy HwB <hwborchers@googlemail.com> - 2011-11-25 10:10 +0000
Re: Root finding needs higher accuracy DrMajorBob <btreat1@austin.rr.com> - 2011-11-26 10:16 +0000
Re: Root finding needs higher accuracy DrMajorBob <btreat1@austin.rr.com> - 2011-11-26 10:18 +0000
Re: Root finding needs higher accuracy Andrzej Kozlowski <akoz@mimuw.edu.pl> - 2011-11-26 11:49 +0000
Re: Root finding needs higher accuracy Andrzej Kozlowski <akoz@mimuw.edu.pl> - 2011-12-06 03:06 +0000
| From | HwB <hwborchers@googlemail.com> |
|---|---|
| Date | 2011-11-24 12:04 +0000 |
| Subject | Root finding needs higher accuracy |
| Message-ID | <jalbrn$sib$1@smc.vnet.net> |
I would like to numerically find the root of the following function
with up to 20 digits.
f12[x_] := Log[x] + x^2 / (2 Exp[1]) - 2 x / Sqrt[Exp[1]] + 1
This problem is known to be difficult for solvers in double precision
arithmetics. I thought it should be easy with Mathematica, but the
following attempts were not successful.
SetPrecision[
x /. FindRoot[f12[x], {x, 1.0, 3.4}, Method -> "Brent",
AccuracyGoal -> Infinity, PrecisionGoal -> 20], 16]
# 1.648732212532746
SetPrecision[
x /. FindRoot[f12[x], {x, 1.0, 3.4}, Method -> "Secant",
AccuracyGoal -> Infinity, PrecisionGoal -> 20], 16]
# 1.648710202030051
The true root obviously is Sqrt[Exp[1]]//N = 1.648721270700128...
The symbolic solver explicitely says it cannot solve this expression.
What do I need to do to get a much more exact result out of
Mathematica?
Many thanks, Hans Werner
[toc] | [next] | [standalone]
| From | "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> |
|---|---|
| Date | 2011-11-25 09:55 +0000 |
| Message-ID | <janom0$ar6$1@smc.vnet.net> |
| In reply to | #6689 |
On Thu, 24 Nov 2011 12:04:07 -0000, HwB <hwborchers@googlemail.com> wrote:
> I would like to numerically find the root of the following function
> with up to 20 digits.
>
> f12[x_] := Log[x] + x^2 / (2 Exp[1]) - 2 x / Sqrt[Exp[1]] + 1
>
> This problem is known to be difficult for solvers in double precision
> arithmetics. I thought it should be easy with Mathematica, but the
> following attempts were not successful.
>
> SetPrecision[
> x /. FindRoot[f12[x], {x, 1.0, 3.4}, Method -> "Brent",
> AccuracyGoal -> Infinity, PrecisionGoal -> 20], 16]
> # 1.648732212532746
> SetPrecision[
> x /. FindRoot[f12[x], {x, 1.0, 3.4}, Method -> "Secant",
> AccuracyGoal -> Infinity, PrecisionGoal -> 20], 16]
> # 1.648710202030051
>
> The true root obviously is Sqrt[Exp[1]]//N = 1.648721270700128...
>
> The symbolic solver explicitely says it cannot solve this expression.
> What do I need to do to get a much more exact result out of
> Mathematica?
>
> Many thanks, Hans Werner
>
This example needs quite high working precision in order to get the right
answer. Why PrecisionGoal doesn't deal with this automatically I am not
sure, but one can see how much precision is required for any given number
of correct output digits by adapting one of the examples from the FindRoot
documentation as follows:
Block[{prec = MachinePrecision},
FindRoot[f12[x], {x, 1.0, 3.4},
PrecisionGoal -> 50, WorkingPrecision -> 250,
MaxIterations -> Infinity,
StepMonitor :> If[Precision[x] != prec,
prec = Precision[x];
Print["Increased precision to ", prec, " at x = ", x];
]
] ~N~ 50
]
Increased precision to 22.5696 at x = 1.6487322125327459332311
Increased precision to 36.5184 at x = 1.648721374841646612577391800\
565954854
Increased precision to 59.0881 at x = 1.648721270702420370629525870\
3627276509506510504319572642272
Increased precision to 95.6065 at x = 1.648721270700128146916322464\
88686398379199745290239060756077856939685227628191642463512718464832
Increased precision to 154.695 at x = 1.648721270700128146848650787\
8142075038521581133809975282156292557669985282581157969309334240808\
833720966852901635178145293354315920227892691746952853066932
{x -> 1.6487212707001281468486507878141635716537761007102}
This gives the correct answer to 50 places, but 250 digits of working
precision is only just enough to achieve this. For your example of 16
correct places, 48 digits of working precision are required.
[toc] | [prev] | [next] | [standalone]
| From | Peter Falloon <pfalloon@gmail.com> |
|---|---|
| Date | 2011-11-25 10:04 +0000 |
| Message-ID | <janp77$b3t$1@smc.vnet.net> |
| In reply to | #6689 |
On Nov 24, 11:04 pm, HwB <hwborch...@googlemail.com> wrote:
> I would like to numerically find the root of the following function
> with up to 20 digits.
>
> f12[x_] := Log[x] + x^2 / (2 Exp[1]) - 2 x / Sqrt[Exp[1]] + 1
>
> This problem is known to be difficult for solvers in double precision
> arithmetics. I thought it should be easy with Mathematica, but the
> following attempts were not successful.
>
> SetPrecision[
> x /. FindRoot[f12[x], {x, 1.0, 3.4}, Method -> "Brent",
> AccuracyGoal -> Infinity, PrecisionGoa=
l -> 20], 16]
> # 1.648732212532746
> SetPrecision[
> x /. FindRoot[f12[x], {x, 1.0, 3.4}, Method -> "Secant",
> AccuracyGoal -> Infinity, PrecisionGoa=
l -> 20], 16]
> # 1.648710202030051
>
> The true root obviously is Sqrt[Exp[1]]//N = 1.648721270700128...
>
> The symbolic solver explicitely says it cannot solve this expression.
> What do I need to do to get a much more exact result out of
> Mathematica?
>
> Many thanks, Hans Werner
You need to increase the WorkingPrecision:
In[658]:= f[x_] := Log[x] + x^2 / (2 Exp[1]) - 2 x / Sqrt[Exp[1]] + 1
x0 = x /. FindRoot[f[x], {x, 1.5}, PrecisionGoal->20, WorkingPrecision-
>30];
{x0, f[x0]}
Out[660]= {1.64872127035488735592446035944, 0.*10^-30}
Cheers,
Peter.
[toc] | [prev] | [next] | [standalone]
| From | HwB <hwborchers@googlemail.com> |
|---|---|
| Date | 2011-11-25 10:10 +0000 |
| Message-ID | <janpin$b7k$1@smc.vnet.net> |
| In reply to | #6689 |
Okay, with the help of Fred Simons, Netherlands, I realized that the
magic keyword here is "WorkingPrecision" --- though I don't understand
how to know an appropriate value for it in advance (I am not using
Mathematica on a regular basis). At least, Mathematica itself is
requesting more iterations if necessary.
SetPrecision[
x /. FindRoot[f12[x], {x, 1, 3.4}, Method -> "Brent",
WorkingPrecision -> 75, MaxIterations -> 250], 20]
1.6487212707001281468
Still, I find it strange that Mathematica cannot solve this expression
symbolically.
Regards
Hans Werner
On Nov 24, 1:04 pm, HwB <hwborch...@googlemail.com> wrote:
> I would like to numerically find the root of the following function
> with up to 20 digits.
>
> f12[x_] := Log[x] + x^2 / (2 Exp[1]) - 2 x / Sqrt[Exp[1]] + 1
>
> This problem is known to be difficult for solvers in double precision
> arithmetics. I thought it should be easy with Mathematica, but the
> following attempts were not successful.
>
> SetPrecision[
> x /. FindRoot[f12[x], {x, 1.0, 3.4}, Method -> "Brent",
> AccuracyGoal -> Infinity, PrecisionGoa=
l -> 20], 16]
> # 1.648732212532746
> SetPrecision[
> x /. FindRoot[f12[x], {x, 1.0, 3.4}, Method -> "Secant",
> AccuracyGoal -> Infinity, PrecisionGoa=
l -> 20], 16]
> # 1.648710202030051
>
> The true root obviously is Sqrt[Exp[1]]//N = 1.648721270700128...
>
> The symbolic solver explicitely says it cannot solve this expression.
> What do I need to do to get a much more exact result out of
> Mathematica?
>
> Many thanks, Hans Werner
[toc] | [prev] | [next] | [standalone]
| From | DrMajorBob <btreat1@austin.rr.com> |
|---|---|
| Date | 2011-11-26 10:16 +0000 |
| Message-ID | <jaqe9r$njp$1@smc.vnet.net> |
| In reply to | #6689 |
Sadly, WorkingPrecision->30 gets us just 10 correct digits:
f[x_] := Log[x] + x^2/(2 Exp[1]) - 2 x/Sqrt[Exp[1]] + 1
root = x /.
FindRoot[f[x], {x, 1.5}, PrecisionGoal -> 20, WorkingPrecision -> 30]
Replace[RealDigits@N[root, 25] - RealDigits@N[Sqrt@E, 25] //
First, {x : Longest[0 ..], ___} :> Length@{x}]
1.64872127035491043009143137899
10
Bobby
On Fri, 25 Nov 2011 03:57:13 -0600, Peter Falloon <pfalloon@gmail.com>
wrote:
> On Nov 24, 11:04 pm, HwB <hwborch...@googlemail.com> wrote:
>> I would like to numerically find the root of the following function
>> with up to 20 digits.
>>
>> f12[x_] := Log[x] + x^2 / (2 Exp[1]) - 2 x / Sqrt[Exp[1]] + 1
>>
>> This problem is known to be difficult for solvers in double precision
>> arithmetics. I thought it should be easy with Mathematica, but the
>> following attempts were not successful.
>>
>> SetPrecision[
>> x /. FindRoot[f12[x], {x, 1.0, 3.4}, Method -> "Brent",
>> AccuracyGoal -> Infinity, PrecisionGoa=
> l -> 20], 16]
>> # 1.648732212532746
>> SetPrecision[
>> x /. FindRoot[f12[x], {x, 1.0, 3.4}, Method -> "Secant",
>> AccuracyGoal -> Infinity, PrecisionGoa=
> l -> 20], 16]
>> # 1.648710202030051
>>
>> The true root obviously is Sqrt[Exp[1]]//N = 1.648721270700128...
>>
>> The symbolic solver explicitely says it cannot solve this expression.
>> What do I need to do to get a much more exact result out of
>> Mathematica?
>>
>> Many thanks, Hans Werner
>
> You need to increase the WorkingPrecision:
>
> In[658]:= f[x_] := Log[x] + x^2 / (2 Exp[1]) - 2 x / Sqrt[Exp[1]] + 1
> x0 = x /. FindRoot[f[x], {x, 1.5}, PrecisionGoal->20, WorkingPrecision-
>> 30];
> {x0, f[x0]}
>
> Out[660]= {1.64872127035488735592446035944, 0.*10^-30}
>
> Cheers,
> Peter.
>
--
DrMajorBob@yahoo.com
[toc] | [prev] | [next] | [standalone]
| From | DrMajorBob <btreat1@austin.rr.com> |
|---|---|
| Date | 2011-11-26 10:18 +0000 |
| Message-ID | <jaqecp$nkd$1@smc.vnet.net> |
| In reply to | #6689 |
Clear[digits]
digits[precision_] := Module[{x, root},
root = x /.
Quiet@FindRoot[f12[x], {x, 1, 3.4}, Method -> "Brent",
WorkingPrecision -> precision, MaxIterations -> 250];
Replace[
RealDigits@N[root, precision] - RealDigits@N[Sqrt@E, precision] //
First, {x : Longest[0 ..], ___} :> Length@{x}]
]
digits@75
ListPlot[{#, digits@#} & /@ Range[17, 80]]
Bobby
On Fri, 25 Nov 2011 03:59:24 -0600, HwB <hwborchers@googlemail.com> wrote:
> Okay, with the help of Fred Simons, Netherlands, I realized that the
> magic keyword here is "WorkingPrecision" --- though I don't understand
> how to know an appropriate value for it in advance (I am not using
> Mathematica on a regular basis). At least, Mathematica itself is
> requesting more iterations if necessary.
>
> SetPrecision[
> x /. FindRoot[f12[x], {x, 1, 3.4}, Method -> "Brent",
> WorkingPrecision -> 75, MaxIterations -> 250], 20]
>
> 1.6487212707001281468
>
> Still, I find it strange that Mathematica cannot solve this expression
> symbolically.
>
> Regards
> Hans Werner
>
>
> On Nov 24, 1:04 pm, HwB <hwborch...@googlemail.com> wrote:
>> I would like to numerically find the root of the following function
>> with up to 20 digits.
>>
>> f12[x_] := Log[x] + x^2 / (2 Exp[1]) - 2 x / Sqrt[Exp[1]] + 1
>>
>> This problem is known to be difficult for solvers in double precision
>> arithmetics. I thought it should be easy with Mathematica, but the
>> following attempts were not successful.
>>
>> SetPrecision[
>> x /. FindRoot[f12[x], {x, 1.0, 3.4}, Method -> "Brent",
>> AccuracyGoal -> Infinity, PrecisionGoa=
> l -> 20], 16]
>> # 1.648732212532746
>> SetPrecision[
>> x /. FindRoot[f12[x], {x, 1.0, 3.4}, Method -> "Secant",
>> AccuracyGoal -> Infinity, PrecisionGoa=
> l -> 20], 16]
>> # 1.648710202030051
>>
>> The true root obviously is Sqrt[Exp[1]]//N = 1.648721270700128...
>>
>> The symbolic solver explicitely says it cannot solve this expression.
>> What do I need to do to get a much more exact result out of
>> Mathematica?
>>
>> Many thanks, Hans Werner
>
--
DrMajorBob@yahoo.com
[toc] | [prev] | [next] | [standalone]
| From | Andrzej Kozlowski <akoz@mimuw.edu.pl> |
|---|---|
| Date | 2011-11-26 11:49 +0000 |
| Message-ID | <jaqjo8$ojc$1@smc.vnet.net> |
| In reply to | #6689 |
On 25 Nov 2011, at 10:59, HwB wrote:
> Okay, with the help of Fred Simons, Netherlands, I realized that the
> magic keyword here is "WorkingPrecision" --- though I don't understand
> how to know an appropriate value for it in advance (I am not using
> Mathematica on a regular basis). At least, Mathematica itself is
> requesting more iterations if necessary.
>
> SetPrecision[
> x /. FindRoot[f12[x], {x, 1, 3.4}, Method -> "Brent",
> WorkingPrecision -> 75, MaxIterations -> 250], 20]
>
> 1.6487212707001281468
>
> Still, I find it strange that Mathematica cannot solve this expression
> symbolically.
>
> Regards
> Hans Werner
I don't find strange at all. Human being do this essentially by guessing
the answers: how can you expect Mathematica to do the same? What
Mathematica can do, and this is quite remarkable, is to solve the
equation "exactly". The following answer is an "exact answer", not an
approximate one:
sols =
x /. Solve[Log[x] + x^2/(2 Exp[1]) - 2 x/Sqrt[Exp[1]] + 1 == 0, x,
Reals]
{Root[{4 #1-4 Sqrt[E]&,1.64872127070012814685}],Root[{4 #1-4
Sqrt[E]&,1.64872127070012814685}],Root[{4 #1-4
Sqrt[E]&,1.64872127070012814685}]}
This is entirely different from finding the roots approximately; here
Mathematica actually proves that there are exactly three roots and that
they are equal. The presence of approximate numbers in the answer does
not mean that the answer itself is approximate, in fact it can be
computed to arbitrary precision:
In[10]:= N[First[sols], 100]
Out[10]= =
1.648721270700128146848650787814163571653776100710148011575079311640661021194215608632776520056366643
You can replace 100 by 1000 if you like. This answer is different from but not in any respect worse than Sqrt[E], which is what you surely expected. Mathematica does not notice the possibility of a further simplification because in the case of transcendental roots it does not attempt to simplify the pure function inside the root object, as it would do in an algebraic case, e.g.
Root[4 #1-4 Sqrt[E]&,1]
Sqrt[E]
Probably this is because the number of situations in which this would be useful is small, but there might also be some other reason. Anyway, it is just possible that this is one respect in which Reduce could be improved, i.e. it could simplify things like
Root[{#1-Sqrt[2]&,1.414213562373095}]
To
Sqrt[2]
as it does in the algebraic case.
Of course it is possible to "guide" Mathematica to the desired answer, e.g.
eq = x^2/(2*E^1) - (2*x)/Sqrt[E^1] + Log[x] + 1 == 0;
eq1 = eq /. x -> Sqrt[E]*u
u^2/2 - 2*u + Log[Sqrt[E]*u] + 1 == 0
Reduce[eq1, u, Reals]
u==1
Andrzej Kozlowski
[toc] | [prev] | [next] | [standalone]
| From | Andrzej Kozlowski <akoz@mimuw.edu.pl> |
|---|---|
| Date | 2011-12-06 03:06 +0000 |
| Message-ID | <jbk0rt$fgf$1@smc.vnet.net> |
| In reply to | #6689 |
Explicit formulas (in radicals) for the solutions of cubics or quartics
are not very "useful", (which is why Solve and Reduce have the Options
Cubics and Quartics) (although their discovery lead directly to the
discovery of complex numbers - which are as "useful" as anything in
mathematics).
However the fact that Mathematica can produce closed form solutions of
polynomial equations of arbitrary degree (this does not contradict
Abel's theorem!) is extremely "useful". Just one example, is the
ability to evaluate things like
Integrate[1/(1 + t + t^3 + t^11), t] // Normal
and lots of other things.
The ability of Reduce to solve exactly many kinds of transcendental
equations and inequalities is tremendously "useful".
(Of course the word "useful" in the context of mathematics is vague and
subject to debate. But people who remember G.H. Hardy's boasts that his
subject, number theory, was and always will remain, entirely "useless"
realise that making such predictions is risky).
Andrzej Kozlowski
On 4 Dec 2011, at 17:27, Ralph Dratman wrote:
> "I don't find strange at all. Human being do this essentially by
> guessing the answers: how can you expect Mathematica to do the same?"
>
> And those guesses used to take decades or centuries to turn up! I have
> read that finding the roots of a general cubic equation was a terribly
> difficult challenge to get in closed form. Mathematica just spits out
> the roots. Is that really useful? I'm not sure, but I agree that it is
> certainly impressive.
>
> Ralph Dratman
>
>
>
> On Sat, Nov 26, 2011 at 6:48 AM, Andrzej Kozlowski <akoz@mimuw.edu.pl>
wrote:
>>
>> On 25 Nov 2011, at 10:59, HwB wrote:
>>
>>> Okay, with the help of Fred Simons, Netherlands, I realized that the
>>> magic keyword here is "WorkingPrecision" --- though I don't
understand
>>> how to know an appropriate value for it in advance (I am not using
>>> Mathematica on a regular basis). At least, Mathematica itself is
>>> requesting more iterations if necessary.
>>>
>>> SetPrecision[
>>> x /. FindRoot[f12[x], {x, 1, 3.4}, Method -> "Brent",
>>> WorkingPrecision -> 75, MaxIterations -> 250], 20]
>>>
>>> 1.6487212707001281468
>>>
>>> Still, I find it strange that Mathematica cannot solve this
expression
>>> symbolically.
>>>
>>> Regards
>>> Hans Werner
>>
>> I don't find strange at all. Human being do this essentially by
guessing
>> the answers: how can you expect Mathematica to do the same? What
>> Mathematica can do, and this is quite remarkable, is to solve the
>> equation "exactly". The following answer is an "exact answer", not an
>> approximate one:
>>
>> sols =
>> x /. Solve[Log[x] + x^2/(2 Exp[1]) - 2 x/Sqrt[Exp[1]] + 1 == 0,
x,
>>
>> Reals]
>>
>> {Root[{4 #1-4 Sqrt[E]&,1.64872127070012814685}],Root[{4 #1-4
>> Sqrt[E]&,1.64872127070012814685}],Root[{4 #1-4
>> Sqrt[E]&,1.64872127070012814685}]}
>>
>> This is entirely different from finding the roots approximately; here
>> Mathematica actually proves that there are exactly three roots and
that
>> they are equal. The presence of approximate numbers in the answer
does
>> not mean that the answer itself is approximate, in fact it can be
>> computed to arbitrary precision:
>>
>> In[10]:= N[First[sols], 100]
>>
>> Out[10]=
>> =
1.648721270700128146848650787814163571653776100710148011575079311640661021194215608632776520056366643
>>
>> You can replace 100 by 1000 if you like. This answer is different from but not in any respect worse than Sqrt[E], which is what you surely expected. Mathematica does not notice the possibility of a further simplification because in the case of transcendental roots it does not attempt to simplify the pure function inside the root object, as it would do in an algebraic case, e.g.
>>
>> Root[4 #1-4 Sqrt[E]&,1]
>>
>> Sqrt[E]
>>
>> Probably this is because the number of situations in which this would be useful is small, but there might also be some other reason. Anyway, it is just possible that this is one respect in which Reduce could be improved, i.e. it could simplify things like
>>
>> Root[{#1-Sqrt[2]&,1.414213562373095}]
>>
>> To
>>
>> Sqrt[2]
>>
>> as it does in the algebraic case.
>>
>> Of course it is possible to "guide" Mathematica to the desired answer, e.g.
>>
>> eq = x^2/(2*E^1) - (2*x)/Sqrt[E^1] + Log[x] + 1 == 0; >>
>> eq1 = eq /. x -> Sqrt[E]*u
>> u^2/2 - 2*u + Log[Sqrt[E]*u] + 1 == 0
>>
>> Reduce[eq1, u, Reals]
>> u==1
>>
>> Andrzej Kozlowski
>>
>>
>>
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web