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
Have a look at Ted Ersek's _RootSearch_ package.
"RootSearch looks for all roots of an equation between xmin and xmax. A
package is provided which defines a function called RootSearch.
RootSearch[lhs==rhs,{x,xmin,xmax}] tries to find all roots in the
specified range. The algorithm is very robust as demonstrated in the
notebook (RootSearchExamples.nb). Options are provided to allow
arbitrary precision convergence to roots. Installation instructions are
provided in the notebook (RootSearchExamples.nb)."
http://library.wolfram.com/infocenter/MathSource/4482/
Best regards,
Jean-Marc
Download and install the Ted Ersek RootSearch package from MathSource.
Although it works only on 1D cases, in those cases it is much better and
more convenient than FindRoot.
Needs["Ersek`RootSearch`"]
RootSearch[Cos[antwoord] == Sin[antwoord], {antwoord, 0, 10Pi}]
{{antwoord -> 0.785398}, {antwoord -> 3.92699}, {antwoord ->
7.06858}, {antwoord -> 10.2102}, {antwoord -> 13.3518}, {antwoord ->
16.4934}, {antwoord -> 19.635}, {antwoord -> 22.7765}, {antwoord ->
25.9181}, {antwoord -> 29.0597}}
David Park
dj...@earthlink.net
http://home.earthlink.net/~djmp/
If the only special functions contained in your equation are
trigonometric and exponential, then you can try interval methods from
the IntervalRoots package. For your example:
Needs["NumericalMath`IntervalRoots`"]
In[2]:=
IntervalNewton[Cos[x]-Sin[x],x,Interval[{0,10Pi}],10^-6,MaxRecursion->10]
Out[2]=
Interval[{0.785398, 0.785398}, {3.92699, 3.92699}, {7.06858, 7.06858},
{10.2102, 10.2102}, {13.3518, 13.3518}, {16.4934, 16.4934}, {19.635,
19.635}, {22.7765, 22.7765}, {25.9181, 25.9181}, {29.0597, 29.0597}]
The nice thing about interval methods is that all roots are guaranteed
to lie in the returned Interval object, although some of the
subintervals may not contain any roots.
Carl Woll
Wolfram Research
For example in the domain [0,Pi/2] we want to solve (I only used FindRoot
because this was the fastest):
I put the package I test in on
http://home.wanadoo.nl/akomur/testRootSearch.nb so that you can see the
formulas I use.
Copying them In here ruins the formulas.
Akil
Daniel
> IntervalRoots package and RootSearch do not work for the kind of formulas I
> have.
Are you sure?
> For example in the domain [0,Pi/2] we want to solve (I only used FindRoot
> because this was the fastest):
>
> I put the package I test in on
> http://home.wanadoo.nl/akomur/testRootSearch.nb so that you can see the
> formulas I use.
>
> Copying them In here ruins the formulas.
Copy as Plain text. Your first formula is
nlv = Max[-81.24275115593154 Cot[beta] - 48.489352280270914,
Min[-46.844746272761526 Cot[beta] - 71.4213555357176,
-46.480384751324436 Cot[beta] - 71.66426321667566]]
Note that PiecewiseExpand can be applied to such formulae. If you
simplify the result
Simplify[PiecewiseExpand[nlv]]
you deduce that nlv is just
-81.24275115593154 Cot[beta] - 48.489352280270914 if Cot[beta] <= 2/3
-46.844746272761526 Cot[beta] - 71.4213555357176 if Cot[beta] >= 2/3
You can check that these values are consistent when Cot[beta] == 2/3.
Moreover, the catch-all condition
-46.480384751324436 Cot[beta] - 71.66426321667566
is redundant for real beta since it only applies when Cot[beta] == 2/3.
A brief examination of nuvb shows that it involves ratios of (powers of)
expressions similar to nlv. I expect that simplification of these
expressions prior to constructing nuvb would lead to a final form that
is not that hard to handle.
I expect that if you step back and tell us more about the original
problem, then a more elegant approach would present itself.
Cheers,
Paul
_______________________________________________________________________
Paul Abbott Phone: 61 8 6488 2734
School of Physics, M013 Fax: +61 8 6488 1014
The University of Western Australia (CRICOS Provider No 00126G)
AUSTRALIA http://physics.uwa.edu.au/~paul