Home > Archive > Mathematica > December 2006 > FindRoot anomaly (example from Mathematica Tutorial)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
FindRoot anomaly (example from Mathematica Tutorial)
|
|
| howardfink@gmail.com 2006-12-13, 4:31 pm |
| FindRoot[3Cos[x] == Log[x], {x, 1}] is on page 12 of the tutorial that
starts up in Mathematica 5.
I was interested in how the seed affects the answer, so I made a table
sol = Table[FindRoot[3Cos[x] == Log[x], {x, b}], {b, 100}];
and then plotted the solutions
ListPlot[x /. sol]
I got a nice table, but the seed of 22 returns {x -> -207.932 +
1.39227 i]}
so the plot returns the error:
Graphics::gptn: Coordinate -207.932 + 1.39227\\[ImaginaryI] in {22,
-207.932 \
+ 1.39227\\[ImaginaryI]} is not a floating-point number.
The other 99 results make a nice plot.
| |
| gardyloo 2006-12-14, 9:09 am |
|
And yet the solutions you get from that FindRoot are mostly incorrect.
Apparently, the default method that FindRoot is using gets hung up when
Cos[x] is approximately +/- 1 (after all, the Newton's method is
expected to go wonky at these particular points). So, for example, the
"root" x->56.542772508541205` (just to pick one at random) does NOT
satisfy the original equation.
Ersek's RootSearch function finds only seven roots to the equation
between x = 1 and x = 100:
sol = RootSearch[3*Cos[x] == Log[x], {x, 1, 100}]
{{x -> 1.447258617277903}, {x -> 5.301987341712279},
{x -> 7.13951454299577}, {x -> 11.970165552607465},
{x -> 13.10638768062491}, {x -> 18.624716143898215},
{x -> 19.0387370100137}}
Possibly ( I haven't tried it) forcing FindRoot to use the secant method
by supplying different starting conditions might make for a more
stringent search.
Regards,
C.O.
howardfink@gmail.com wrote:
> FindRoot[3Cos[x] == Log[x], {x, 1}] is on page 12 of the tutorial that
> starts up in Mathematica 5.
> I was interested in how the seed affects the answer, so I made a table
>
> sol = Table[FindRoot[3Cos[x] == Log[x], {x, b}], {b, 100}];
>
> and then plotted the solutions
>
> ListPlot[x /. sol]
>
> I got a nice table, but the seed of 22 returns {x -> -207.932 +
> 1.39227 i]}
>
> so the plot returns the error:
> Graphics::gptn: Coordinate -207.932 + 1.39227\\[ImaginaryI] in {22,
> -207.932 \
> + 1.39227\\[ImaginaryI]} is not a floating-point number.
>
> The other 99 results make a nice plot.
>
>
>
--
========================================
==================
Curtis Osterhoudt
gardyloo@mail.remove_this.wsu.and_this.edu
PGP Key ID: 0x088E6D7A
Please avoid sending me Word or PowerPoint attachments
See http://www.gnu.org/philosophy/no-word-attachments.html
========================================
==================
--------------000801010502040909070705
Content-Type: text/x-vcard; charset="utf-8"; name="gardyloo.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="gardyloo.vcf"
X-Sun-Content-Length: 296
YmVnaW46dmNhcmQNCmZuOkN1cnRpcyAgT3N0ZXJo
b3VkdA0KbjpPc3RlcmhvdWR0O0N1cnRp
cyANCmVtYWlsO2ludGVybmV0OmdhcmR5bG9vQG1h
aWwucmVtb3ZlX3RoaXMud3N1LmFuZF90
aGlzLmVkdQ0KdGVsO3dvcms6NTA5LjMzNS40OTQ2
DQpub3RlOlBHUCBLZXkgSUQ6IDB4MDg4
RTZEN0ENCngtbW96aWxsYS1odG1sOkZBTFNFDQp2
ZXJzaW9uOjIuMQ0KZW5kOnZjYXJkDQoN
Cg==
--------------000801010502040909070705--
| |
| dimitris 2006-12-15, 8:14 am |
| In my opinion is not an anomaly!
It just happens the implemented algorithm to return a complex number
for this seed choise.
The important is that Mathematica returns the correct answer!
The following cell demonstrates Mathematica's cabability:
f[x_] := 3*Cos[x] - Log[x]
Print[StyleForm["the function", FontColor -> Blue]]; f[x]
Print[StyleForm["a plot of the function", FontColor -> Blue]];
Plot[f[x], {x, 0, 60}]
plot = Plot[f[x], {x, 1, 60}, DisplayFunction -> Identity];
Print[StyleForm["the points used by the Plot function ", FontColor ->
Blue]];
points = Cases[plot, {(x_)?NumberQ, (y_)?NumberQ}, Infinity]
Print[StyleForm["find where the function changes sign", FontColor ->
Blue]];
seeds = Position[Apply[Times, Partition[points[[All,2]], 2, 1], {1}],
x_ /; x <= 0]
Print[StyleForm["between this points in x axis there is a change in
sign of f[x]", FontColor -> Blue]];
samples = Extract[Partition[points[[All,1]], 2, 1], seeds]
Print[StyleForm["the roots, at last!", FontColor -> Blue]];
(FindRoot[f[x] == 0, {x, #1[[1]], #1[[2]]}] & ) /@ samples
Regards
Dimitris
Ï/Ç howardfink@gmail.com Ýãñáøå:
> FindRoot[3Cos[x] == Log[x], {x, 1}] is on page 12 of the tutorial that
> starts up in Mathematica 5.
> I was interested in how the seed affects the answer, so I made a table
>
> sol = Table[FindRoot[3Cos[x] == Log[x], {x, b}], {b, 100}];
>
> and then plotted the solutions
>
> ListPlot[x /. sol]
>
> I got a nice table, but the seed of 22 returns {x -> -207.932 +
> 1.39227 i]}
>
> so the plot returns the error:
> Graphics::gptn: Coordinate -207.932 + 1.39227\\[ImaginaryI] in {22,
> -207.932 \
> + 1.39227\\[ImaginaryI]} is not a floating-point number.
>
> The other 99 results make a nice plot.
|
|
|
|
|