Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include <cmath>
- #include <cstdio>
- double mysinh(double x, double eps, int &k, double &rn) {
- double s = 0;
- double u = x;
- k = 1;
- while (fabs(u) >= eps) {
- s += u;
- u = x * x / (2 * k * (2 * k + 1)) * u;
- k++;
- }
- rn = u;
- return s;
- }
- int main() {
- double a = -1.8;
- double b = 1.9;
- double x = (a + b) * 0.5;
- double h = (b - a) / 9.0;
- int n = 0;
- double rn = 0;
- printf("| eps | n | abs error | rem term |\n");
- for (double eps = 1e-2; eps > 1e-14; eps *= 1e-2) {
- double y = mysinh(x, eps, n, rn);
- printf("| %.0e | %2i | %8.5e | %12.5e |\n", eps, n, fabs(sinh(x) - y), fabs(rn));
- }
- printf("\n| xi | abs error | rem term |\n");
- for (int i = 0; i < 10; i++) {
- double x = a + h * i;
- double y = mysinh(x, 1e-8, n, rn);
- printf("| %6.2f | %8.5e | %12.5e |\n", x, fabs(sinh(x) - y), fabs(rn));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement