Re: using FindRoot to find multiple answers in a domain?
- To: mathgroup at smc.vnet.net
- Subject: [mg69134] Re: using FindRoot to find multiple answers in a domain?
- From: dh <dh at metrohm.ch>
- Date: Wed, 30 Aug 2006 06:36:02 -0400 (EDT)
- References: <ed0rn9$sm6$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hello Akil, finding all the roots af a general function is no trivial task. The best you can do, is to solve the problem analytically. Try exploiting analytical properties of your function. If this is out of question, you may try FindRoot with different starting values. Make a plot for rough values of the roots. To automate, chose the starting values on a grid over the given region. For your example, the plot: Plot[{Sin[x], Cos[x]}, {x, 0, 10Pi}] gives you an idea about the roots, starting values for FindRoot. We expect to find 10 roots. If you want to use a grid of starting values, you could use: d= x/. FindRoot[Cos[x] == Sin[x], {x, #}] & /@ Range[0, 10Pi, 0.1] this gives values outside our region and multiple copies of some roots. To restrict the values to the region and to get unique values: d = Select[d, 0 <= # <= 10Pi &]; Union[d, SameTest -> (Abs[#1 - #2] < 10^-6 &)] now we have the expected 10 values. Daniel akil wrote: > I want to find all answers that exist in a certain domain, but FindRoot > gives only the first answer it finds (Using other methods like Solve,Reduce > etc takes too long, so Im stuck with using FindRoot). I give the problem I > have by example, the functions I use are really complex, but by solving the > problem for the example, I could solve t for the complex part. > > Example: > > Finding all intersections of Cos[x] and Sin[x] in the domain [0,10Pi] > > Doing: > FindRoot[Cos[antwoord] == Sin[antwoord], {antwoord, 0, 0, 10Pi}] > > FindRoot[Cos[antwoord] == Sin[antwoord], {antwoord, %, %, 10Pi}] > > does not work the second FindRoot gives the exact same answer back. So using > this in a loop to find all intersections does not work. > > Doing FindRoot[Cos[antwoord] == Sin[antwoord], {antwoord, %+0.01, %+0.01, > 10Pi}] instead, also does not work. > > Any way to find all intersections in a specified domain? > > Akil > >