Функция atan
Функция atan вычисляет арктангенс и возвращает значение арктангенса параметра agl . В тригонометрии, арктангенс является обратной тригонометрической функцией тангенса.
Обратите внимание, что из-за двусмысленности знака, функция не может точно определить, в каком квадранте находится значение угла. Для этого, вы можете использовать функцию atan2 , если нужно определить квадрант.
В C++, эта функция перегружена в <valarray> (см. atan в библиотеке массивов числовых значений) .
В Си, определён только один прототип этой функции, с типом данных double .
Как найти арктангенс в с
Returns the principal value of the arc tangent of x , expressed in radians.
In trigonometrics, arc tangent is the inverse operation of tangent.
Notice that because of the sign ambiguity, the function cannot determine with certainty in which quadrant the angle falls only by its tangent value. See atan2 for an alternative that takes a fractional argument instead.
Additional overloads are provided in this header ( <cmath> ) for the integral types: These overloads effectively cast x to a double before calculations (defined for T being any integral type).
Calculating the value of arctan(x) in C++
I have to calculate the value of arctan(x) . I have calculated the value of this by evaluating the following series :
But the following code can not calculate the actual value. For example, calculate_angle(1) returns 38.34 . Why?
3 Answers 3
EDIT: I found the culprit. You forgot to include stdlib.h , where the function abs resides. You must have ignored the warning about abs being implicitly declared. I checked that removing the include yields the result 38.19 and including it yields the result
The compiler is not required to stop compilation when an undeclared function is being used (in this case abs). Instead, it is allowed to make assumptions on how the function is declared (in this case, wrong one.)
Besides, like other posters already stated, your use of abs is inappropriate as it returns an int, not a double or float. The condition in the while should be >1e-100 not <1e-100 . The 1e-100 is also too small.
You forgot to increase count and power after calculating the first two summands:
Also I consider your use of the count variable counterintuitive: it is intialized with 3 like if it denotes the last used power; but then, loop iterations increase it by 1 instead of 2 and you decide the sign by count%2 == 1 as opposed to power%4 == 3