Search code examples
methodstrigonometryangle

Which tan method to use?


When I solve tan(3.14) with calculator,it gives 0.0548582.

When I solve with Math.tan the answer is 0.0014. When I solve with Math.atan the answer is 1.26.

Which tan method to use so that i get answer like my calculator gives and how?

    package testclass;

    public class TestClass {
    public static void main(String[] args) {      
      System.out.println(Math.atan(3.14)); 
      System.out.println(Math.tan(3.143));
      }
    }

Solution

  • First of all: Under no circumstance should tan(3.14) be +0.0014; you've pasted it with the wrong sign.

    This is not a programming question.

    The three functions you use are different functions:

    • atan is arcustangens, i.e. the inverse to tan, so it's completely unrelated.
    • your calculator seems to use degrees
    • your Math.tan function uses radians. 3.14 is "pretty close, but a little smaller" than pi, and sin(3.14) is thus pretty close, but a little bigger than 0, cos(3.14) is thus pretty close, but a little smaller (in absolute terms) than -1, so tan(3.14) is a little less than 0.

    EDIT: tan x = sin x/cos x, to explain my calculations above.