Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/numeric/complex/cos"

From cppreference.com
< cpp‎ | numeric‎ | complex
(+detail, example)
m (fmt, headers sorted)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{cpp/title|cos{{small|(std::complex)}}}}
 
{{cpp/title|cos{{small|(std::complex)}}}}
 
{{cpp/numeric/complex/navbar}}
 
{{cpp/numeric/complex/navbar}}
{{ddcl | header=complex | 1=
+
{{ddcl|header=complex|1=
 
template< class T >  
 
template< class T >  
 
complex<T> cos( const complex<T>& z );
 
complex<T> cos( const complex<T>& z );
 
}}
 
}}
  
Computes complex cosine of a complex value {{tt|z}}.
+
Computes complex cosine of a complex value {{c|z}}.
  
 
===Parameters===
 
===Parameters===
 
{{par begin}}
 
{{par begin}}
{{par | z | complex value}}
+
{{par|z|complex value}}
 
{{par end}}
 
{{par end}}
  
 
===Return value===
 
===Return value===
  
If no errors occur, the complex cosine of {{tt|z}} is returned.
+
If no errors occur, the complex cosine of {{c|z}} is returned.
  
Errors and special cases are handled as if the operation is implemented by {{c|std::ccosh(i*z)}}, where {{tt|i}} is the imaginary unit.
+
Errors and special cases are handled as if the operation is implemented by {{tt|[[cpp/numeric/complex/cosh|std::cosh]](i * z)}}, where {{tt|i}} is the imaginary unit.
  
 
===Notes===
 
===Notes===
 
The cosine is an entire function on the complex plane, and has no branch cuts.
 
The cosine is an entire function on the complex plane, and has no branch cuts.
  
Mathematical definition of the cosine is {{math|cos z {{=}} {{mfrac|e{{su|p=iz}}+e{{su|p=-iz}}|2}}}}
+
Mathematical definition of the cosine is {{math|cos z {{=}} {{mfrac|e{{su|p=iz}}+e{{su|p=-iz}}|2}}}}.
  
 
===Example===
 
===Example===
{{example |
+
{{example
| code=
+
|code=
#include <iostream>
+
 
#include <cmath>
 
#include <cmath>
 
#include <complex>
 
#include <complex>
 +
#include <iostream>
  
 
int main()
 
int main()
 
{
 
{
 
     std::cout << std::fixed;
 
     std::cout << std::fixed;
     std::complex<double> z(1, 0); // behaves like real cosine along the real line
+
     std::complex<double> z(1.0, 0.0); // behaves like real cosine along the real line
 
     std::cout << "cos" << z << " = " << std::cos(z)
 
     std::cout << "cos" << z << " = " << std::cos(z)
 
               << " ( cos(1) = " << std::cos(1) << ")\n";
 
               << " ( cos(1) = " << std::cos(1) << ")\n";
  
     std::complex<double> z2(0, 1); // behaves like real cosh along the imaginary line
+
     std::complex<double> z2(0.0, 1.0); // behaves like real cosh along the imaginary line
 
     std::cout << "cos" << z2 << " = " << std::cos(z2)
 
     std::cout << "cos" << z2 << " = " << std::cos(z2)
 
               << " (cosh(1) = " << std::cosh(1) << ")\n";
 
               << " (cosh(1) = " << std::cosh(1) << ")\n";
 
}
 
}
| output=
+
|output=
 
cos(1.000000,0.000000) = (0.540302,-0.000000) ( cos(1) = 0.540302)
 
cos(1.000000,0.000000) = (0.540302,-0.000000) ( cos(1) = 0.540302)
 
cos(0.000000,1.000000) = (1.543081,-0.000000) (cosh(1) = 1.543081)
 
cos(0.000000,1.000000) = (1.543081,-0.000000) (cosh(1) = 1.543081)
Line 48: Line 48:
 
===See also===
 
===See also===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc inc | cpp/numeric/complex/dsc sin}}
+
{{dsc inc|cpp/numeric/complex/dsc sin}}
{{dsc inc | cpp/numeric/complex/dsc tan}}
+
{{dsc inc|cpp/numeric/complex/dsc tan}}
{{dsc inc | cpp/numeric/complex/dsc acos}}
+
{{dsc inc|cpp/numeric/complex/dsc acos}}
{{dsc inc | cpp/numeric/math/dsc cos}}
+
{{dsc inc|cpp/numeric/math/dsc cos}}
{{dsc inc | cpp/numeric/valarray/dsc cos}}
+
{{dsc inc|cpp/numeric/valarray/dsc cos}}
{{dsc see c | c/numeric/complex/ccos}}
+
{{dsc see c|c/numeric/complex/ccos}}
 
{{dsc end}}
 
{{dsc end}}
  
[[de:cpp/numeric/complex/cos]]
+
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}
[[es:cpp/numeric/complex/cos]]
+
[[fr:cpp/numeric/complex/cos]]
+
[[it:cpp/numeric/complex/cos]]
+
[[ja:cpp/numeric/complex/cos]]
+
[[pt:cpp/numeric/complex/cos]]
+
[[ru:cpp/numeric/complex/cos]]
+
[[zh:cpp/numeric/complex/cos]]
+

Latest revision as of 23:08, 21 April 2023

 
 
 
 
Defined in header <complex>
template< class T >
complex<T> cos( const complex<T>& z );

Computes complex cosine of a complex value z.

Contents

[edit] Parameters

z - complex value

[edit] Return value

If no errors occur, the complex cosine of z is returned.

Errors and special cases are handled as if the operation is implemented by std::cosh(i * z), where i is the imaginary unit.

[edit] Notes

The cosine is an entire function on the complex plane, and has no branch cuts.

Mathematical definition of the cosine is cos z =
eiz+e-iz
2
.

[edit] Example

#include <cmath>
#include <complex>
#include <iostream>
 
int main()
{
    std::cout << std::fixed;
    std::complex<double> z(1.0, 0.0); // behaves like real cosine along the real line
    std::cout << "cos" << z << " = " << std::cos(z)
              << " ( cos(1) = " << std::cos(1) << ")\n";
 
    std::complex<double> z2(0.0, 1.0); // behaves like real cosh along the imaginary line
    std::cout << "cos" << z2 << " = " << std::cos(z2)
              << " (cosh(1) = " << std::cosh(1) << ")\n";
}

Output:

cos(1.000000,0.000000) = (0.540302,-0.000000) ( cos(1) = 0.540302)
cos(0.000000,1.000000) = (1.543081,-0.000000) (cosh(1) = 1.543081)

[edit] See also

computes sine of a complex number (sin(z))
(function template) [edit]
computes tangent of a complex number (tan(z))
(function template) [edit]
computes arc cosine of a complex number (arccos(z))
(function template) [edit]
(C++11)(C++11)
computes cosine (cos(x))
(function) [edit]
applies the function std::cos to each element of valarray
(function template) [edit]