Re: FindRoot for an oscillating function
- To: mathgroup at smc.vnet.net
- Subject: [mg50936] Re: FindRoot for an oscillating function
- From: drbob at bigfoot.com (Bobby R. Treat)
- Date: Tue, 28 Sep 2004 00:59:05 -0400 (EDT)
- References: <cj86qq$78r$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Here's an approach that takes advantage of the Plot itself. It finds consecutive data points that bracket roots, averages the x-values, uses those as guesses in FindRoot, and finally graphs the original function with roots superimposed. It will only find roots internal to the plotted interval, so I reduced the lower limit to get the root at zero. Needs["Graphics`"] p = 1.234; q = .7654; gr[x_] = Sin[p x]/p + Sin[q x]/q; plot = Plot[gr@x, {x, -1, 25}, DisplayFunction -> Identity]; points = First@Cases[plot, Line[a_] -> a, Infinity]; guesses = Mean /@ Extract[Partition[points[[All, 1]], 2, 1], Position[Partition[points[[All, -1]], 2, 1], _?(Times @@ # <= 0 &), {1}]] roots = x /. FindRoot[gr@x, {x, #}] & /@ guesses rootPts = {#, gr@#} & /@ roots DisplayTogether[plot, Graphics at {PointSize[0.02], Red, Point /@ rootPts}, DisplayFunction -> $DisplayFunction]; Bobby mathma18 at hotmail.com (Narasimham G.L.) wrote in message news:<cj86qq$78r$1 at smc.vnet.net>... > How to find all real/complex roots by sweeping through the domain > {x,0,25} using Mathematica capability? p = 1.234; q = .7654; gr = Sin[p x]/p > + Sin[q x]/q ; Plot[gr,{x, 0, 25}]; FindRoot[gr == 0, {x, 0, 25}]