       Re: FindRoot

• To: mathgroup at smc.vnet.net
• Subject: [mg8902] Re: FindRoot
• From: Paul Abbott <paul at physics.uwa.edu.au>
• Date: Thu, 2 Oct 1997 22:56:54 -0400
• Organization: University of Western Australia
• Sender: owner-wri-mathgroup at wolfram.com

```David Djajaputra wrote:

> I need to plot the root of a transcendental equation
>
> sin(x)=x/a,     for a from 2 to 3.
>
> I can find the root for each a using FindRoot. But how do I make a
> continuous plot using FindRoot?

Using ListPlot with PlotJoined->True is one way to do what you want,
i.e.,

In:=
ListPlot[Table[{a,x/.FindRoot[Sin[x]==x/a,{x,2}]},{a,2,3,0.05}],
PlotJoined->True];

For another approach, see the Mathematica Journal 3(3):28.  I have
attached a Mathematica 3.0 Notebook below relevant for your example.

Cheers,
Paul

____________________________________________________________________
Paul Abbott                                   Phone: +61-8-9380-2734
Department of Physics                           Fax: +61-8-9380-1014
The University of Western Australia
Nedlands WA  6907                     mailto:paul at physics.uwa.edu.au
AUSTRALIA                             http://www.pd.uwa.edu.au/~paul

God IS a weakly left-handed dice player
____________________________________________________________________

Notebook[{

Cell[CellGroupData[{
Cell["Root Finding with a Parameter", "Section",
CellTags->"root finding"],

Cell[TextData[{
"Suppose that we wish to find the roots of the transcendental equation
",
Cell[BoxData[
" where ",
Cell[BoxData[
" is a parameter. For a fixed value of ",
Cell[BoxData[
", this can be easily accomplished using the ",
Cell[BoxData[
FormBox[
StyleBox["FindRoot",
" command. For example, if ",
Cell[BoxData[
" then to find the root near ",
Cell[BoxData[
" we use"
}], "Text",
CellTags->{"FindRoot", "transcendental equation"}],

Cell[CellGroupData[{

Cell[BoxData[
\(TraditionalForm\`start = {2, x /. FindRoot(sin(x) == x\/2, {x,
2})}\)],
"Input"],

Cell[BoxData[
}, Open  ]],

Cell[TextData[{
"An efficient technique for finding the values of a root as a function
of \
the parameter is to use the functional iteration operation ",
Cell[BoxData[
FormBox[
StyleBox["NestList",
". First, define a function whose first argument is the parameter:"
}], "Text",
CellTags->{"functional iteration", "NestList"}],

Cell[BoxData[
\(TraditionalForm\`f(a_, x_) := sin(x) - x\/a\)], "Input"],

Cell[TextData[{
"Then step along the ",
Cell[BoxData[
"-axis by ",
Cell[BoxData[
" and find the root of the transcendental equation using the previous
root \
as an initial guess:"
}], "Text",
CellTags->"iterative guessing"],

Cell[BoxData[
\`FRStep(f_, {a_, x_}, h_:  0.05) :=
Module({b}, {a + h, b /. FindRoot(f(a + h, b) == 0, {b, x})})\)],
"Input"],

Cell[CellGroupData[{

Cell[BoxData[

Cell[BoxData[
"Output"]
}, Open  ]],

Cell[TextData[{
"That is, at ",
Cell[BoxData[
", ",
StyleBox["x",
FontSlant->"Italic"],
" is approximately 1.92368. ",
Cell[BoxData[
FormBox[
StyleBox["NestList",
" can then be used to create a list of the roots in the form ",
Cell[BoxData[
":"
}], "Text"],

Cell[BoxData[
"Input"],

Cell[BoxData[