If the library function is not called, evaluate sin (X)

Source: Internet
Author: User
Tags cos

The first is the Taylor formula, but the formula brother does not remember it. If you are interested, it is not difficult to find out the implementation.

Second recursion, using three formulas

Sin (x) = 2 * sin (X/2) * Cos (X/2) -------------- Formula 1

Cos (x) = SQRT (1-sin (x) * sin (x) -------------- formula 2

Lim SiNx = x, when x tends to 0 ----------------- Formula 3

The problem of sin (X) is decomposed into the problem of sin (X/2), and then recursion is ended using Formula 3.

# Include <iostream> # include <math. h> using namespace STD; double ssin (Double X) {If (x <0.0000001) // defines an infinitely small return X; double result = ssin (X/2 ); return 2 * result * SQRT (1-result * result); // use Formula 1 and formula 2} int main () {Double X; CIN> X; fflush (stdin); cout <ssin (x) <Endl; getchar (); Return 0 ;}

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.