====== cos() ======
cos wird in C über math.h, bzw. in C++ über cmath eingebunden.
===== Funktion =====
Die Funktion errechnet den Cosinus eines Winkels. Die Rückgabe liegt im Bereich zwischen -1 und 1.
| {{c:lib:math:einheitskreis_sin_cos_tan.jpg?150}} | __Im Einheitskreis:__ α ist hierbei der Winkel. Der Rückgabewert entspricht der Länge der grünen Strecke. \\ Der Cosinus beschreibt den Abstand zur X-Achse, also der Y-Koordinate |
===== Signatur =====
double cos ( double x );
float cos ( float x ); /* nur in C++ */
long double cos ( long double x ); /* nur in C++ */
long double cosl( long double x );
float cosf( float x );
**x**: Winkel (im [[theory:math:trigonometry:angular-dimensions|Bogenmaß]]), dessen Cosinus berechnet werden soll.
**Return Value**: Berechneter Cosinus.
===== Fehlerquellen =====
Der Winkel muss im [[theory:math:trigonometry:angular-dimensions|Bogenmaß]] (0 bis 2*π) angegeben werden, nicht im Grad (0 bis 360) oder Neugrad (0 bis 400).
===== Beispiel =====
#include // für EXIT_SUCCESS
#include // für sin, cos
#include // für printf()
#define PI 3.141592654
int main( void )
{
double radian, degree = 90;
double x, y;
radian = degree / 180 * PI; // Grad in Radial umrechnen
y = sin( radian );
x = cos( radian );
printf( "%f Grad: x-Laenge: %f, y-Laenge: %f\n", degree, x, y );
return EXIT_SUCCESS;
}
Ausgabe:
90.000000 Grad: x-Laenge: 1.000000, y-Laenge: -0.000000
===== Hinweis =====
In C++ wird diese Funktion mit einem ValueArray-Template überladen.
===== Siehe auch =====
[[c:lib:math:start|math]]: [[c:lib:math:sin()]], [[c:lib:math:tan()]], [[c:lib:math:asin()]], [[c:lib:math:acos()]], [[c:lib:math:atan()]] \\
[[cpp:lib:valarray:start|ValArray]]: [[cpp:lib:valarray:cos()]], [[cpp:lib:valarray:sin()]], [[cpp:lib:valarray:tan()]], [[cpp:lib:valarray:acos()]], [[cpp:lib:valarray:asin()]], [[cpp:lib:valarray:atan()]] \\
\\
[[theory:math:trigonometry:start|Trigometrie]]: [[theory:math:trigonometry:angular-dimensions|Winkelmaße]]