[Date Index]
[Thread Index]
[Author Index]
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[1]:=
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[
\(TraditionalForm\`Sin[x] = \ x/a\)]],
" where ",
Cell[BoxData[
\(TraditionalForm\`a\)]],
" is a parameter. For a fixed value of ",
Cell[BoxData[
\(TraditionalForm\`a\)]],
", this can be easily accomplished using the ",
Cell[BoxData[
FormBox[
StyleBox["FindRoot",
"Input"], TraditionalForm]]],
" command. For example, if ",
Cell[BoxData[
\(TraditionalForm\`a = 2\)]],
" then to find the root near ",
Cell[BoxData[
\(TraditionalForm\`x = 2\)]],
" 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[
\(TraditionalForm\`{2, 1.89549426720871316`}\)], "Output"]
}, 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",
"Input"], TraditionalForm]]],
". 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[
\(TraditionalForm\`a\)]],
"-axis by ",
Cell[BoxData[
\(TraditionalForm\`h\)]],
" and find the root of the transcendental equation using the previous
root \
as an initial guess:"
}], "Text",
CellTags->"iterative guessing"],
Cell[BoxData[
\(TraditionalForm
\`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[
\(TraditionalForm\`FRStep(f, start)\)], "Input"],
Cell[BoxData[
\(TraditionalForm\`{2.04999999999999982`, 1.92367954032495482`}\)],
"Output"]
}, Open ]],
Cell[TextData[{
"That is, at ",
Cell[BoxData[
\(TraditionalForm\`a = 2.05\)]],
", ",
StyleBox["x",
FontSlant->"Italic"],
" is approximately 1.92368. ",
Cell[BoxData[
FormBox[
StyleBox["NestList",
"Input"], TraditionalForm]]],
" can then be used to create a list of the roots in the form ",
Cell[BoxData[
\(TraditionalForm\`{a, x}\)]],
":"
}], "Text"],
Cell[BoxData[
\(TraditionalForm\`\(NestList(FRStep(f, #)&, start, 20); \)\)],
"Input"],
Cell[BoxData[
\(TraditionalForm\`\(ListPlot(%, PlotJoined \[Rule] True); \)\)],
"Input"]
}, Open ]]
}
]
Prev by Date:
**Re: prograMing: split a list**
Next by Date:
**Re: a[[2]][[3]] = 1 error? why?**
Previous by thread:
**Re: FindRoot**
Next by thread:
**Fwd: FindRoot**
| |