Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<math.h>
- using namespace std;
- int faktorial(int N) {
- if (N == 0 || N == 1) return 1;
- return N * faktorial(N-1);
- }
- double myexp(double x, int n) {
- double e = 0.;
- for (int i=0; i<=n; i++)
- e += pow(x, i) / faktorial(i);
- return e;
- }
- double sinh_(double x, int N) {
- double sinh_x = (myexp(x, N) - myexp(-x, N)) / 2;
- return sinh_x;
- }
- int main() {
- int N = 10;
- double x = 0.5;
- // mencari sinh 0.5 - function bawaan math.h vs manual sinh_
- double yx = sinh(x);
- double y = sinh_(x, N);
- double galat = abs(yx - y);
- printf("%.20f\n%.20f\nGalat: %.20f", yx, y, galat);
- }
Advertisement
Add Comment
Please, Sign In to add comment