Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #define _USE_MATH_DEFINES
- #include <math.h>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "rus");
- double xn = 2 * M_PI, epsilon = 1e-6;
- int i = 0;
- double x = 0;
- while (x <= xn) {
- double cosxt = 1;
- int k = 2;
- double el = -x*x / 2;
- cosxt += el;
- while (fabs(el) > epsilon) {
- k += 2;
- el = -el*x*x / (k*(k - 1)); //Слагаемое для cos
- cosxt += el;
- }
- cout << "Количество слагаемых для косинуса = " << k / 2 << endl;
- double sinxt = x;
- k = 3;
- el = -x*x*x / 6; //fact(3) = 6
- sinxt += el;
- while (fabs(el) > epsilon) {
- k += 2;
- el = -el*x*x / (k*(k - 1)); //Слагаемое для sin
- sinxt += el;
- }
- cout << "Количество слагаемых для синуса = " << (k - 1) / 2 << endl;
- double xt = cosxt + sinxt;
- cout << "Значение по Тейлору = " << cosxt + sinxt << endl;
- cout << "Значение по встроенным функциям = " << cos(x) + sin(x) << endl;
- i++;
- x = i*0.1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement