# Jump discontinuities

## Homework Statement:

When I try to plot the following function I encounter jump discontinuities that should not exist according to various papers. What is the cause of the problem?

## Relevant Equations:

I am trying to plot the function:

$$\Theta=\pi+\varphi+\text{atan}\left(\frac{r\sin\varphi}{\tau-r\cos\varphi}\right)+\text{atan}\left(\frac{r\tau\sin\varphi}{1-r\tau\cos\varphi}\right).$$

for the three cases where $r=\tau$, $r<\tau$, and $r>\tau$. My problem is with the latter case.
Here is a picture of these plots from a paper:

When I try to reproduce the 3rd graph above (yellow line below), I get sharp discontinuities:

Those jump discontinuities should not occur, and the function should never rise to the high value of the two other plots. So, what could be the cause of this problem?

Any suggestions would be appreciated.

Related Calculus and Beyond Homework Help News on Phys.org
Math_QED
Homework Helper
2019 Award
The only way discontinuities can arise is when you divide by 0. Have you calculated where one of the denominators in your expression becomes 0 and where the discontinuity arises? Did you get a match?

George Jones
Staff Emeritus
Gold Member
Problem Statement: When I try to plot the following function I encounter jump discontinuities that should not exist according to various papers. What is the cause of the problem?
I am not sure, but I think that atan is giving you values in the the wrong quadrant. This is something you always have to take care with when using a calculator or computer.

For example, $\tan \beta = 0$ when $\beta =0$, but $\tan \beta = 0$, also when $\beta = -\pi$.

For example, when $\varphi = \pi$, the arguments of the atans are both zero. If the atans both return zero, then
$$\Theta = \pi +\pi + 0 + 0 = 2 \pi .$$

If, however, the atans both return $-\pi$, then
$$\Theta = \pi +\pi -\pi -\pi = 0.$$

It should be possible to figure out what is actually happening.

What George said above.
Look up the atan2 function, that will probably fix this.

FactChecker
Gold Member
Print or plot the intermediate calculations for the atan terms and it should become obvious. It is possible to detect and cancel steps like that to get a continuous function, but the implementation depends on what language you are using. I have only done it in a couple of languages.

Thanks for all the suggestions. I tried the method suggested by @DaveE and @George Jones and used atan2. But I am still not quite getting the correct plot. Here is the result (yellow line):

The problem is that, the plot should not take the form of a staircase function. Unlike the two other curves, it should not keep going up. What is the problem here?

Here is what I should get from another paper (the bottom plot):

P.S. I am using Matlab. Here is the code:

Matlab:
r=0.9; tau=0.65;
phi = [-1*pi:0.0001:4*pi];
Phi=pi + phi + atan2((r*sin(phi))./(tau-r*cos(phi)),phi)+atan2((r*tau)*sin(phi)./(1-r*tau*cos(phi)),phi);
plot(phi,Theta)

FactChecker
Gold Member
I can not emphasize this enough: When a complicated equation is misbehaving, break it up and look at smaller parts.
You are using atan2 wrong. It should be like atan2((r*sin(phi)), (tau-r*cos(phi)))

The first atan2 still has jump discontinuities. MATLAB has an unwrap function that will stop the jumps and return a continuous variable. The second atan2 has no jumps in that case, but it is good to unwrap it also, just in case.

I think this code will give you what you wanted.

MATLAM code with corrected atan2 and unwrapped terms:
r=0.9; tau=0.65;
phi = [-1*pi:0.0001:4*pi];

term1 =  atan2((r*sin(phi)), (tau-r*cos(phi)));
plot(phi,term1) % 1
unwrap1 = unwrap(term1, 3.1/2);
figure
plot(phi,unwrap1) % 2

figure
term2 = atan2((r*tau)*sin(phi), (1-r*tau*cos(phi)));
plot(phi,term2) %3
unwrap2 = unwrap(term2, 3.1/2);
figure
plot(phi,unwrap2) % 4

figure
Theta=pi + phi + unwrap1 + unwrap2;
plot(phi,Theta) % 5

Last edited:
Hi FactChecker,

It works perfectly. Thank you so much for your time.

P.S. How did you choose the optimal value for the jump tolerance?

FactChecker