# Troubleshooting Jump Discontinuities: Causes & Solutions

• roam
In summary, the conversation discusses the problem of jump discontinuities in reproducing a plot from a paper. Various suggestions are given, including using the atan2 function and unwrapping the results. Ultimately, the solution is found by breaking down the equation and examining each term separately. The optimal value for the jump tolerance is chosen based on the size of the jumps in the plot.
roam
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.

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?

roam said:
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.

roam and DaveE
What George said above.
Notice that your jumps are exactly π radians.
Look up the atan2 function, that will probably fix this.

roam and FactChecker
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.

roam
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)

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:
roam
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?

roam said:
P.S. How did you choose the optimal value for the jump tolerance?
I didn't really choose an "optimal" value. It must be large enough to not be fooled by a small step from one value to the next, but small enough not to miss a wrapping jump that may be somewhat obscured by a step from one value to the next. A jump of 3.1/2 is about right to know that the angle has been "wrapped" at that point without missing any.

roam

## What are jump discontinuities?

Jump discontinuities are sudden changes or jumps in the value of a function at a specific point. They can occur in both continuous and discrete functions and are characterized by a sudden change in the slope or direction of the function.

## What are the causes of jump discontinuities?

Jump discontinuities can have various causes, including errors in data collection or measurement, incorrect mathematical calculations, or physical limitations. They can also occur due to abrupt changes in the environment or system being studied.

## How can jump discontinuities be identified?

Jump discontinuities can be identified by examining the graph of a function and looking for sudden changes or discontinuities in the curve. They can also be identified by analyzing the data and looking for sudden changes in the values of the function.

## What are some common solutions for troubleshooting jump discontinuities?

One common solution for troubleshooting jump discontinuities is to carefully review the data and calculations to ensure accuracy. Another solution is to use smoothing techniques, such as averaging or interpolation, to reduce the impact of the jumps. In some cases, it may also be necessary to adjust the experimental setup or parameters to reduce the occurrence of jump discontinuities.

## How can jump discontinuities be prevented?

To prevent jump discontinuities, it is important to carefully design experiments and data collection methods to minimize errors and inconsistencies. It is also important to use appropriate mathematical techniques and algorithms to analyze the data and identify any potential jumps. Regularly checking and calibrating equipment can also help prevent jump discontinuities.

• Calculus and Beyond Homework Help
Replies
2
Views
1K
• Calculus and Beyond Homework Help
Replies
2
Views
1K
• General Math
Replies
2
Views
2K
• High Energy, Nuclear, Particle Physics
Replies
7
Views
3K
• Advanced Physics Homework Help
Replies
4
Views
3K
• Sci-Fi Writing and World Building
Replies
7
Views
2K
• Materials and Chemical Engineering
Replies
2
Views
2K
• Calculus
Replies
3
Views
5K
• Electrical Engineering
Replies
7
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K