I'm newbie here, and using Mathematica for two weeks, so, anyone can help me with this? I tried using the Findroot
command but I don't get it. Thanks in advance guys.
-
$\begingroup$ Possible duplicate: mathematica.stackexchange.com/questions/176257/… $\endgroup$– Michael E2Commented Aug 20, 2018 at 0:02
2 Answers
f[x_] := BesselJ[0, x]
Plot[f[x], {x, 0, 15},
Epilog -> {Red, AbsolutePointSize[4],
Tooltip[Point[{BesselJZero[0, #], 0}], BesselJZero[0, #] // N] & /@
Range[5]}]
To see the progressive estimates using Newton-Raphson, use FixedPointList
(sol1a = Table[
FixedPointList[# - f[#]/f'[#] &, x0], {x0, 3., 15, 3}]) // Column
To see just the final values use FixedPoint
(sol1b = Table[FixedPoint[# - f[#]/f'[#] &, x0], {x0, 3., 15, 3}])
(* {2.40483, 5.52008, 8.65373, 11.7915, 14.9309} *)
Alternatively, using NestList
or Nest
(sol2a = Table[
NestList[# - f[#]/f'[#] &, x0, 10], {x0, 3., 15., 3.}]) // Column
(sol2b = Table[Nest[# - f[#]/f'[#] &, x0, 10], {x0, 3., 15., 3.}])
(* {2.40483, 5.52008, 8.65373, 11.7915, 14.9309} *)
Using FindRoot
sol3 = x /. FindRoot[BesselJ[0, x] == 0, {x, #}] & /@ Range[3., 15, 3]
(* {2.40483, 5.52008, 8.65373, 11.7915, 14.9309} *)
Using NSolve
sol4 = x /. NSolve[{BesselJ[0, x] == 0, 0 < x < 15}, x]
(* {2.40483, 5.52008, 8.65373, 11.7915, 14.9309} *)
Solve
or Reduce
give the solution in terms of BesselJZero
x /. Solve[{BesselJ[0, x] == 0, 0 < x < 15}, x]
(* {BesselJZero[0, 1], BesselJZero[0, 2], BesselJZero[0, 3], BesselJZero[0, 4],
BesselJZero[0, 5]} *)
x /. {ToRules[Reduce[{BesselJ[0, x] == 0, 0 < x < 15}, x]]}
(* {BesselJZero[0, 1], BesselJZero[0, 2], BesselJZero[0, 3], BesselJZero[0, 4],
BesselJZero[0, 5]} *)
Comparing with the BesselJZero
values
bjz = BesselJZero[0, #] & /@ Range[5];
sol1a[[All, -1]] == sol1b == sol2a[[All, -1]] == sol2b == sol3 == sol4 == bjz
(* True *)
-
$\begingroup$ thanks for the answer, but I do not have a formula, that's what I do not understand, how do I apply it? $\endgroup$– shatmanCommented Aug 20, 2018 at 13:10
-
$\begingroup$ You gave Newton-Raphson formula, i.e.,
x[i+1] == x[i] - f[x[i]]/f'[x[i]]
. When written as apure function
the RHS is# - f[#]/f'[#] &
.FixedPointList
andFixedPoint
iterate this pure function until the results converge and stops automatically.NestList
andNest
iterates the pure function a specified number of times. For a sufficiently large number of specified iterations the result will converge to the fixed point. In all of these cases a starting value (x[0]) must be specified that is in the region of the desired root. $\endgroup$ Commented Aug 20, 2018 at 14:35 -
$\begingroup$ thanks Bob, Now I understand it all $\endgroup$– shatmanCommented Aug 20, 2018 at 19:41
f[x_] := BesselJ[0, x]
x[0] = 1.;(*initial point*)(*different initial point converge to different root*)
Table[x[i + 1] = x[i] - f[x[i]]/f'[x[i]]; x[i], {i, 0, 10}]
{1., 2.73889, 2.36779, 2.40456, 2.40483, 2.40483, 2.40483, 2.40483,2.40483, 2.40483, 2.40483}
x[0] = 5.;(*initial point*)
Table[x[i + 1] = x[i] - f[x[i]]/f'[x[i]]; x[i], {i, 0, 10}]
{5., 5.54215, 5.52003, 5.52008, 5.52008, 5.52008, 5.52008, 5.52008, 5.52008, 5.52008, 5.52008}
-
$\begingroup$ thank you this was very helpful :) $\endgroup$– shatmanCommented Aug 20, 2018 at 13:12