Re: ALL roots of non-polynomial equation
- To: mathgroup at smc.vnet.net
- Subject: [mg35956] Re: ALL roots of non-polynomial equation
- From: Selwyn Hollis <slhollis at earthlink.net>
- Date: Fri, 9 Aug 2002 05:18:04 -0400 (EDT)
- References: <aitgk4$cr3$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Mihajlo,
Here's a little program that works fairly well. It detects sign changes
over a mesh of points to determine initial guesses for FindRoot. The
"res" parameter is the mesh size.
allRoots[fn_, {x_, a_, b_}, res_] := FindRoot[fn, {x,#}]& /@
Module[{meshpoints = Table[x, {x,a,b,res}], vals},
vals = fn /. x->meshpoints;
meshpoints[[Flatten[Position[Drop[vals*RotateRight[vals], 1],
_?(NonPositive[#]&)]]]] + .5*res]
If the mesh isn't fine enough, some roots will be missed. For example,
allRoots[Sin[3x^2]-.3x, {x, 0, 4}, .1]
doesn't give all the roots in the interval, but this does:
allRoots[Sin[3x^2]-.3x, {x, 0, 4}, .01]
---
Selwyn Hollis
slhollis at mac.com
Mihajlo Vanevic wrote:
> Can Mathematica find (localize) ALL roots of non-polynomial equation
>
> eq[x]==0
>
> on a given segment x \in [a,b], a,b=Real??
>
> (for example Sin[x]==0, for 0.1<x<10.1 Pi )
>
>
>
>
>