Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Evaluation on branch cuts

Subject: Evaluation on branch cuts

From: tsg.moore@googlemail.com

Date: 23 May, 2009 14:26:00

Message: 1 of 3

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.

Subject: Evaluation on branch cuts

From: Roger Stafford

Date: 23 May, 2009 22:04:02

Message: 2 of 3

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

Subject: Evaluation on branch cuts

From: Roger Stafford

Date: 24 May, 2009 00:00:03

Message: 3 of 3

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gv9rsi$9uk$1@fred.mathworks.com>...
> ......
> a = mod(angle(x)+pi-e,2*pi)-pi+e;
> f = sqrt(abs(x))*exp(a/2*i);
> ......

  On that branch cut shifting method I gave you earlier I think it would be preferable to do things as follows. Once only at the beginning of a program, do this:

 e1 = exp(-e*i); e2 = exp(e/2*i);

where e was the small, aformentioned quantity. Then for each different x do this:

 f = sqrt(x*e1)*e2;

This will be faster, more accurate, and quite obviously more convenient.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us