arctangent

In the simulation, you will need to use arctangent (or inverse tangent) to compute the phase Ψ(t) of the bridge. You need to know that there are two numpy functions to compute arctangent. They are called arctan() and arctan2(). We recommend you to use arctan2(). Let us explain.

In this assignment, you will need to compute arctangent of numbers of the form x1/x2. This computation is tricky if x2 is zero, or if both x1 and x2 are zero. If x2 is zero and you use arctan(x1/x2) in numpy, you will get a divison by zero error. However, mathematically, the arctangent of 1/0 is legitimate and is equal to pi/2. That is why, many programming languages provide an alternative method to compute arctangent. In Python, this alternative method is arctan2().

If you want to compute the arctangent of x1/x2 with arctan2(), you write arctan2(x1,x2). The following picture shows a few examples of using arctan2() when x2 is zero. Note that pi/2 is approximately 1.57. 

If x2 is non-zero, the arctan2(x1,x2) is the same as arctan(x1/x2).

If you want to go back to the main assignment page, click here.