|
tsg.moore@googlemail.com wrote in message <5f739eb0-78ce-4ad6-9b63-4333abbf5e73@s28g2000vbp.googlegroups.com>...
> I always have trouble with Matlab's determination of which value to
> use when a function is evaluated on its branch cut. For example,
> evaluating the function f(z) = z^(1/2) along the negative real axis.
>
> Is there a way to get Matlab to automatically insert a small imaginary
> value in order to keep the signs sorted out? For example, I may want
> to use,
>
> f(x + 1e-12*i) as the value of f(x)
>
> That is, other than doing it manually. I suppose my question is are
> there any aids to help the programmer keep control over how Matlab is
> performing the branch cuts.
Your question is rather vaguely stated, but I am guessing you are concerned by possible rounding errors present in the input x. In effect, you wish to slightly move a standard branch cut in some favored direction so that such errors are not sufficient to cause erratic crossings back and forth across the standard cut. There is something of a logical fallacy in such an endeavor, in that this will simply move the neighborhood in which rounding errors can cause these effects. There is no way of preventing this rounding error "chaos" from occurring across a cut location no matter where that cut is placed.
Also it seems clear to me that each branch cut situation must be dealt with individually and appropriately. It is unrealistic to suppose that matlab could be induced to use some "automatic" method that applies to everything. Each function has its own unique characteristics.
For your square root example, adding a constant 1e-12*i seems inappropriate. For very large numbers it is ineffective, for very small numbers it is too drastic, and worst of all, it affects answers everywhere, not just in the vicinity of the cut. For better performance I would suggest just rotating the branch cut angle a tiny amount counterclockwise. I suspect that is actually what you had in mind. This can be accomplished (at some sacrifice in speed and convenience) as follows:
a = mod(angle(x)+pi-e,2*pi)-pi+e;
f = sqrt(abs(x))*exp(a/2*i);
where e is some small radian angle such as your 1e-12.
The answers in f should only be affected for x lying in the corresponding tiny wedge just counterclockwise from the negative real axis. Crossings of the negative real axis will thus not cause the sudden changes that occur in sqrt(x). However, crossing the lower side of the wedge will now take over the role of erratic behavior as warned above.
Roger Stafford
|