Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- float y(float x) {
- return sinh(pow(x, 2) - 3) + 4.0 / sinh(pow(x, 2) + 3);
- }
- float sinh_teulor(float x, int c) {
- float y = 0;
- float f = 1; // 1! = 1 3!
- for (int i = 1; i <= c; ++i) {
- // i 1: x
- // i 2: x ^ 3 / 3 !
- // i 3: x ^ 5 / 5 !
- y += pow(x, i * 2 - 1) / f;
- f *= (2 * i + 1) * (2 * i);
- }
- return y;
- }
- float y_teulor(float x, int c) {
- return sinh_teulor(pow(x, 2) - 3, c) + 4 / sinh_teulor(pow(x, 2) + 3, c);
- }
- int main()
- {
- float x, eps;
- cin >> x >> eps;
- float y1, y2;
- y1 = y_teulor(x, 1);
- y2 = y_teulor(x, 2);
- int i = 3;
- while (abs(y2 - y1) > eps) {
- y1 = y2;
- y2 = y_teulor(x, i);
- i += 1;
- }
- cout << "y~=" << y2 << "\n";
- cout << "y=" << y(x) << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement