Summarizing the correlation function of cosine in C language _c language

Source: Internet
Author: User
Tags acos cos

C language cos () function: Cosine value
header file:

#include <math.h>

The Cos () function is used to find the cosine value, that is, the ratio of the side length of the angle to the length of the hypotenuse, and the prototype is:

 Double cos (double x);

The "parameter" x is a radian.

Return value returns the calculated result from 1 through 1.

The relationship between radians and angles is:
radians = 180/π angle
Angle =π/180 radians

Use the Rtod () function to convert radian values to angle values.

Note that when compiling with GCC, please join-LM.

"instance" asks for the cosine of two angles and outputs,

#include <stdio.h>
#include <math.h>
int main (void)
{
  double angl,result;
  Angl = 1;
  result = cos (ANGL),/* Cosine value/
  printf ("cos (%LF) is%lf\n", angl,result);/* Formatted output/
  Angl = 3.1415926;
  result = cos (ANGL)/* Cosine//
  printf ("cos (%LF) is%lf\n", angl,result);/* formatted output/return
  0;
}

Run Result:

Cos (1.000000) is 0.540302
cos (3.141593) is-1.000000

The parameters in the program are the Radian values that are used directly, and if you only know the angle, you can use the angle multiplied by the π/180 method to get the Radian value.

C language Cosh () function: To find hyperbolic residual Xuan value
header file:

#include <math.h>

Cosh () is used to compute the hyperbolic residual value of the parameter x, and then returns the result. Its prototype is:

  Double cosh (double x);

The mathematical definition of hyperbolic cosine is:

  (exp (x) +exp (x))/2

That

Note that when compiling with GCC, please join-LM.

Hyperbolic cosine is a function image on the interval-5 <= x <= 5.

The "instance" asks for a hyperbolic cosine of 0.5.

#include <math.h>
Main () {
  Double answer = cosh (0.5);
  printf ("cosh (0.5) =%f\n", answer);
}

Run Result:

cosh (0.5) = 1.127626

Another example is to find the value of a point on the hyperbolic cosine.

#include <stdio.h>
#include <math.h>
int main (void)
{
  double resut;
  Double x =1;
  Resut = cosh (x);/* Seek hyperbolic cosine
  /printf ("cosh (%LF) =%lf\n", x,resut);/* formatted output/return
  0;
}

Run Result:

Cosh (1.000000) = 1.543081

The program first defines two double variables, Resut saves the computed result, and X provides the hyperbolic cosine function point. The function of the statement resut = cosh (x) is to find the value corresponding to the X point on the function and assign the result to the Resut.

C language ACOs () function: To find the value of the inverse cosine
header file:

#include <math.h>

The ACOs () function returns an inverse cosine, in radians, whose prototype is:

  Double ACOs (double x);

The parameter x is the cosine value, ranging from 1 to 1, and exceeding this range will cause an error and set the errno value to EDOM.


Return value returns the result of the calculation between 0 and π, in radians, and in radians in the function library.

The relationship between radians and angles is:
radians = 180/π angle
Angle =π/180 radians

Note: Please join-LM when compiling with GCC.

The "instance" asks for a 0.5 inverse cosine.

#include <math.h>
Main () {
  double angle;
  Angle = ACOs (0.5);
  printf ("angle =%f\n", angle);
}

Run Result:

Angle = 1.047198

For example, the cosine value is the corresponding angle.

#include <stdio.h>
#include <math.h>
int main (void)
{
  double angl,result;
  Angl = 1;
  Result =acos (cos (ANGL))//* negation cosine/
  printf ("ACOs (%LF) is%lf\n", cos (ANGL), result);/* Formatted output/
  Angl = 3.1415926;
  result = ACOs (cos (ANGL)),/* negation cosine/
  printf ("ACOs (%LF) is%lf\n", cos (ANGL), result);/* formatted output/return
  0;
}

Run Result:

ACOs (0.540302) is 1.000000
ACOs ( -1.000000) is 3.141593

This example can be learned from the cosine function example, where the cosine is used as the parameter and then the ACOs () function is used to find the angle for comparison.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.