ComplexRoots
- To: mathgroup at yoda.physics.unc.edu
- Subject: ComplexRoots
- From: akyildiz at maths.ox.ac.uk ( Yilmaz Akyildiz tel 2-73558)
- Date: Fri, 20 Nov 92 14:36:06 GMT
Please discard the earlier version.
(*
This is a Mathematics V.2.0 programme allowing the user to
numerically compute all the common roots of the two real functions
f1 and f2 of two variables x1 and x2 on a given rectangle in the
(x1, x2)-plane. It can easily be generalized to higher dimensions.
comroots[{f1, f2}, {x1, a, b}, {x2, c, d}, tolerance]
will find all the common roots of the functions f1(x1, x2) and
f2(x1, x2) with accuracy correct to the tolerance.
It uses a version of Interval Bisection Method.
For example:
comroots[{x1 Sin[x2] -1, x2 Cos[x1] + 1},
{x1, 0, 5}, {x2, 0, 9}]
finds all the roots of {x1 Sin[x2] -1 = 0, x2 Cos[x1] + 1 = 0}
in the intervals 0 <= x1 <= 5 and 0 <= x2 <= 9 with accuracy correct to
(the default) 3 decimal digits.
In case f1 and f2 are real and imaginary parts of a single
function f, the result will be all the (real and complex) roots of the
function f(x) in the specified rectangle.
For most standard functions (such as POLYNOMIALS, rationals, trigonometric
and hyperbolic functions) the separation into real and imaginary parts
can be automated and the following expression
cxroots[f(x), {x1, a, b}, {x2, c, d}, tol]
will find all the real and complex roots of f in the rectangle
[a, b] x [c, d]. For example, try
cxroots[x^5 -x +1, {x1, 0, 5}, {x2, 0, 10}]
(sorry for the repetitions in the output...)
Similarly,
cxroots[x Tanh[x] - 1, {x1, 0, 10}, {x2, 0, 10}]
will find all the roots of x Tanh[x] -1 on [0, 10] x [0, 10].
The output will be displayed in terms of the Mathematica built-in
function RealInterval. {RealInterval[{x1,x2}], RealInterval[{y1,y2}]
will stand for the root which is contained in the closed
rectangle [x1, x2] x [y1, y2]. This output format is preferable
since Mathematica can do arithmetic with RealInterval objects.
This is a rather slow programme. Faster versions, using
Secant and Newton's methods, are also available.
The buil-in function RealInterval is not yet bug-free.
I would be interested to know if you come across any anomolies
related to this package.
Yilmaz Akyildiz
akyildiz at maths.oxford.ac.uk
*)
ri[x_, y_] := RealInterval[{x, y}]
leftup[{ri[x1_, x2_], ri[y1_, y2_]}] :=
{ri[x1, (x1+x2)/2.], ri[(y1+y2)/2., y2]} // N
leftdown[{ri[x1_, x2_], ri[y1_, y2_]}] :=
{ri[x1, (x1+x2)/2.], ri[y1, (y1+y2)/2.]} // N
rightup[{ri[x1_, x2_], ri[y1_, y2_]}] :=
{ri[(x1+x2)/2., x2], ri[(y1+y2)/2., y2]} // N
rightdown[{ri[x1_, x2_], ri[y1_, y2_]}] :=
{ri[(x1+x2)/2., x2], ri[y1, (y1+y2)/2.]} // N
quadrasect[rect_] := {leftup[rect], leftdown[rect],
rightup[rect], rightdown[rect]}
containszero[{ri[x1_, x2_], ri[y1_, y2_]}] :=
(x1 <= 0 <= x2) && (y1 <= 0 <= y2)
F[{f1_,f2_}, {a_RealInterval,b_RealInterval}] :=
{f1, f2} /. {x1->a, x2->b}
comroots[{f1_, f2_}, {x1_, a_, b_}, {x2_, c_, d_}, tol_:0.00001] :=
With[{step = Select[Flatten[(quadrasect/@#),1],
containszero[N[F[{f1,f2},#]]]&]& },
Nest[step, N[{{ri[a, b], ri[c, d]}}],
Ceiling[Log[2, N[Max[b-a,d-c]/tol]]]]
]
reim[f_] :=ComplexExpand[{Re[f/.x->x+I y],Im[f/.x->x+I y]}]
cxroots[f_,{x1_, a_, b_}, {x2, c_, d_}, tol_:0.0001] :=
comroots[reim[f]/. {x->x1, y->x2}, {x1, a, b}, {x2, c, d}, tol]