rfq

soal 1- sinus hiperbolik maclaurin

rfq
Feb 8th, 2023 (edited)
968
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include<iostream>
  2. #include<math.h>
  3.  
  4. using namespace std;
  5.  
  6. int faktorial(int N) {
  7.     if (N == 0 || N == 1) return 1;
  8.     return N * faktorial(N-1);
  9. }
  10.  
  11. double myexp(double x, int n) {
  12.     double e = 0.;
  13.    
  14.     for (int i=0; i<=n; i++)
  15.         e += pow(x, i) / faktorial(i);
  16.    
  17.     return e;
  18. }
  19.  
  20. double sinh_(double x, int N) {
  21.     double sinh_x = (myexp(x, N) - myexp(-x, N)) / 2;
  22.     return sinh_x;
  23. }
  24.  
  25. int main() {
  26.    
  27.     int N = 10;
  28.  
  29.     double x = 0.5;
  30.    
  31.     // mencari sinh 0.5 - function bawaan math.h vs manual sinh_
  32.     double yx = sinh(x);
  33.     double y = sinh_(x, N);
  34.    
  35.     double galat = abs(yx - y);
  36.     printf("%.20f\n%.20f\nGalat: %.20f", yx, y, galat);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment