Can someone tell me where can I find any implementation of this?
Or perhaps point me in some direction as to how I can get started in implementing it myself?
--
Daniel Huber
Metrohm Ltd.
Oberdorfstr. 68
CH-9100 Herisau
Tel. +41 71 353 8585, Fax +41 71 353 8907
E-Mail:<mailto:d...@metrohm.com>
Internet:<http://www.metrohm.com>
The built-in function FindRoot will readily compute the zeros to
whatever precision you need. You just need to specify one or two
starting guesses.
If you need to find all zeros in a fixed domain (e.g. the interval 0
<= x <= Pi), a neat trick is to leverage the Plot function's adaptive
capabilities (i.e. computing sufficient points to capture the
structure of interest) to get the approximate locations of the zeros,
then refine these using FindRoot.
Here is a simple implementation:
mathieuCZeros[r_,q_] := Module[{ce, lineElts, crossings, z},
(* define ce function *)
ce[z_] := MathieuC[MathieuCharacteristicA[r,q], q, z];
(* get line elements from plot *)
lineElts = Cases[Plot[ce[z], {z,0,Pi}], Line[___], Infinity][[1,1]];
(* get x values on either side of all zero crossings *)
crossings = Select[Partition[lineElts,2,1], Sign[#[[1,2]]] == -
Sign[#[[2,2]]] &][[All,All,1]];
(* find zeros between each crossing using secant method *)
z /. FindRoot[ce[z], {z,#1,#2}] & @@@ crossings
]mathieuCZeros[r_,q_] := Module[{ce, lineElts, crossings, z},
(* define ce function *)
ce[z_] := MathieuC[MathieuCharacteristicA[r,q], q, z];
(* get line elements from plot *)
lineElts = Cases[Plot[ce[z], {z,0,Pi}], Line[___], Infinity][[1,1]];
(* get x values on either side of all zero crossings *)
crossings = Select[Partition[lineElts,2,1], Sign[#[[1,2]]] == -
Sign[#[[2,2]]] &][[All,All,1]];
(* find zeros between each crossing using secant method *)
z /. FindRoot[ce[z], {z,#1,#2}] & @@@ crossings
]
This can be extended as required to handle MathieuS, other domains,
higher precision, possible zeros on boundaries, etc.
Cheers, P.
> Date: Thu, 4 Mar
2010 05:31:00 -0500
> From: pfal...@gmail.com
> Subject:
Re: Mathieu function zeros
> To: math...@smc.vnet.net
One quick way would be too identify all local extrema within the plot
and test whether they are really zero. The following is a skeletal
implementation for minima (can be easily extended to cover maxima):
(* define a test function *)
f[x_] := Sin[x]^2
(* define domain *)
{xmin, xmax} = {0, 10*Pi};
(* get points from plot *)
pts = Cases[Plot[f[x], {x,xmin,xmax}], Line[___], Infinity][[1,1]];
(* define functions to test if middle point of a triple is a minimum
*)
minCheck = #[[2,2]]<#[[1,2]] && #[[2,2]]<#[[3,2]] &;
(* get local minima *)
minPts = Select[Partition[pts, 3, 1], minCheck][[All,All,1]];
(* refine minima to higher accuracy and get in the form (xmin, fmin)
*)
minSols = {x/.#[[2,1]], #[[1]]} & /@
(FindMinimum[f[x], {x, #[[1]], #[[3]]}] & /@ minPts);
(* get a reference value to determine the "scale" of the function *)
refVal = Max[Abs[pts[[All,2]]]];
(* select those minima which are essentially zero according to the
scale of the plot *)
zeros = Select[minSols, PossibleZeroQ[#[[2]]+refVal-refVal] &][[All,
1]]
Plot[f[x], {x,xmin,xmax}, Epilog->{Red, PointSize[0.02], Point[{#,0}]&/
@zeros}]
Cheers, P.
PS: in my previous response I was remiss in neglecting to mention that
I originally got the idea of using Plot in this way from Paul Abbott:
Ted's routine is extremely convenient for searching for zeros along a real
line. It gets all the zeros, crossing and non-crossing, in order within an
interval. It is a specialized but common case of the FindRoot functionality
and Mathematica has nothing like it. It really should be an optional method
for FindRoot.
David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/
From: becko BECKO [mailto:beck...@hotmail.com]
Thanks a lot. This is VERY useful. As you said, I extended it to handle
the other Mathieu's and it worked very well. I think the only issue is
that this method doesn't detect zeros where the graph doesn't cross the
axis (it doesn't detect the zero of x^2, but it does detect the zero of
x^3). This is not an issue with Mathieu functions. But it would be nice
if one could exploit the inner workings of Plot a bit more to detect
zeros that are not crossings. Any ideas?
> Date: Thu, 4 Mar
2010 05:31:00 -0500
> From: pfal...@gmail.com
> Subject:
Re: Mathieu function zeros
> To: math...@smc.vnet.net
>
> On Mar 3, 9:53 pm, becko BECKO <becko...@hotmail.com>
wrote:
David was right that RootSearch is very good at finding zeros where a
function does not change sign. If you have a specific example that is a
problem send me an email at ( Ted....@navy.mil ) and I will trouble
shoot.
David was also right that the message about setting $MinPrecision to
(-Infinity) can be ignored.
I am almost finished with an upgrade to the package that accounts for
several changes in Mathematica since the package was last updated. I
expect to have the new package posted on MathSource within a week.
You can always find the package by searching for "RootSearch" at
http://library.wolfram.com/
Regards,
Ted Ersek
Get my popular Mathematica Tips and Tricks from
http://library.wolfram.com/infocenter/MathSource/4557/
Note: My Tips, Tricks are still relevant, but haven't been updated
since May, 2004.