• Support PF! Buy your school textbooks, materials and every day products Here!

Jump discontinuities

  • #1
1,266
11

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:

244814


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

244815


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

Any suggestions would be appreciated.
 

Answers and Replies

  • #2
Math_QED
Science Advisor
Homework Helper
2019 Award
1,370
496
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?
 
  • #3
George Jones
Staff Emeritus
Science Advisor
Gold Member
7,261
790
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.
 
  • #4
408
296
What George said above.
Notice that your jumps are exactly π radians.
Look up the atan2 function, that will probably fix this.
 
  • #5
FactChecker
Science Advisor
Gold Member
5,322
1,905
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.
 
  • #6
1,266
11
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):

244849

244850


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

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

244851


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)
 
  • #7
FactChecker
Science Advisor
Gold Member
5,322
1,905
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:
  • #8
1,266
11
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?
 
  • #9
FactChecker
Science Advisor
Gold Member
5,322
1,905
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.
 

Related Threads for: Jump discontinuities

Replies
3
Views
3K
Replies
2
Views
2K
  • Last Post
Replies
4
Views
3K
  • Last Post
Replies
2
Views
1K
  • Last Post
Replies
3
Views
2K
  • Last Post
Replies
10
Views
751
Top