MATLAB Answers

# Strange behavior with symbolic and atan

7 views (last 30 days)
Tony Tse on 29 May 2018
Commented: Walter Roberson on 29 May 2018
Hello,
I am solving a time derivative equation in Matlab. atan is part of the solution. It seems to behave strangely when atan(tan) is around. Although, I am not sure. I have attached the script with my problem. This represents a simple circuit in real life.
In the first part of the script, I represented 10e-9 as rational representation, sym(10e-9, 'r'). This seems to give me discontinuity when tan -> inf, at t=0.5 in this case. To my surprise, representing 10e-9 as a floating point in the second part, solves this problem and give me very close results compared to the real world data! Moreover (maybe unrelated), analysing vSol in the second part show parts that go to 0 but isn't simplified!
I would like to get more idea of what is going on before solving a more complicated problem.
Thanks.

#### 0 Comments

Sign in to comment.

### Answers (1)

Walter Roberson on 29 May 2018
The oddity you see in the plot is the correct theoretical form.
After substitution of f = 1, there is a subexpression which is arctan(tan(pi*t)/sqrt(3)) . The tan goes to infinity as t = 1/2 from the left, and since tan is discontinuous, the tan goes to -infinity as t = 1/2 from the right. arctan() therefore goes to pi/2 from the left but -pi/2 from the right. Taking into account the other parts of the expression, the limit from the left is 3000*exp(-(1/30)*sqrt(3)) and the limit from the right is 3000*exp((1/30)*sqrt(3))

#### 2 Comments

Tony Tse on 29 May 2018
Thanks, Walter. That makes sense but what about the 2nd case? It matches the measured data, and not the 1st case.
Walter Roberson on 29 May 2018
It appears that with the round-off error of converting the floating point version, that the expression ends up with subtracting off an arctan(tan(2*pi*f*t)) term; I guess that ends up canceling out the problem somehow because both arctan() would be on the same side of zero ?

Sign in to comment.

Sign in to answer this question.