Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1.  
  2. //qaLa
  3. public class Test {
  4. public final static double EPSILON = 1E-16;
  5.  
  6. public static int faCtorial(int x){
  7. int result = 1;
  8. for (int i = 1; i<=x; i++){
  9. result = result * i;
  10. }
  11. return result;
  12. }
  13.  
  14. /**
  15. * @param x
  16. * @return
  17. */
  18. public static double sinh(final double x) {
  19. double xQuad = x*x;
  20. double delta = x;
  21. double result = x;
  22. int i = 1;
  23. while (true){
  24. delta = xQuad*Math.pow(x,2*i + 1) / faCtorial(2*i + 1);
  25. result += delta;
  26. i++;
  27. double newResult = result + (delta / faCtorial(i));
  28. if (Math.abs(newResult)-Math.abs(result) < EPSILON){
  29. break;
  30. }
  31. }
  32. return result; //replace
  33. }
  34.  
  35. public static void main(String[] args) {
  36. System.out.println("sinh(0)=" + sinh(0.0));
  37. System.out.println("sinh(1)=" + sinh(1.0));
  38. System.out.println("sinh(-1)=" + sinh(-1.0));
  39. System.out.println("sinh(1000)=" + sinh(1000.0));
  40. System.out.println("faculty check: "+ faCtorial(5));
  41. }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement