Arctan En Dev C++

  1. Arctan Function C
  2. Arctan En Dev C Pdf

I have to calculate the value of arctan(x). I have calculated the value of this by evaluating the following series: Arctan (x) = x – x^3/3 + x^5/5 – x^7/7 + x^9/9 - But the following code can not calculate the actual value. For example, calculateangle(1) returns 38.34. The atan function in C returns the inverse tangent of a number (argument) in radians. Tutorials Examples Course Index Explore Programiz Python C C Java Kotlin Swift C# DSA Start Learning Python Explore Python Examples. Popular Tutorials. Get Started Operators. If.else while Loop. For Loop List.

C++

Arctan Function C

Arctan

Arctan En Dev C Pdf

P: n/a
Marc Schellens wrote:
Does anybody know an easy way to get the atan of a complex number in C++?
thanks,
marc

tan(cplx) = sin(cplx)/cos(cplx)
cplx= real + i*imag
sin(i*imag) = i * sinh(imag)
sinh(imag) = ( exp(imag) - exp(-imag) )/2
cos(i*imag) = cosh(imag)
cosh(imag) = ( exp(imag) + exp(-imag) )/2
then
sin(cplx) = sin(real)*cosh(imag) + sinh(imag)*cos(real)
cos(cplx) = cos(real)&cosh(imag) - sin(real)*sinh(imag)
so finally
tan( real + i * imag ) =
sin(real)*cosh(imag) + i * sinh(imag)*cos(real)
-----------------------------------------------
cos(real)&cosh(imag) - i * sin(real)*sinh(imag)
- this leads to this:
template <typename T>
std::complex<T> tan( const std::complex<T> & theta )
{
register T r = theta.real();
register T v = theta.imag();
T exp_v = exp(v);
T exp_mv = 1/exp_v; // same as exp(-v)
T cos_r = cos(r);
T cosh_v = ( exp_v + exp_mv ) / 2;
T sin_r = sin(r);
T sinh_v = ( exp_v - exp_mv ) / 2;
std::complex<T> numerator( sin_r*cosh_v, cos_r*sinh_v );
std::complex<T> denominator( cos_r*cosh_v, - sin_r*sinh_v );
return numerator / denominator;
}
- I didn't check it, I'll leave that exercise to you.
If performance is critical, I suspect that you can do better than this.