Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. //qaLa
  2. public class Program {
  3. public final static double EPSILON = 1E-16;
  4. //EPSILON defined
  5. public static double faCtorial(double x){
  6. //factorial function
  7. double result = 1;
  8. for (double 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. //sinh method
  20. double delta = x;
  21. double result = x;
  22. int i = 1;
  23. while (true){
  24. //always true, unless interrupted by break
  25. delta = Math.pow(x, 2*i+1) / faCtorial(2*i+1);
  26. result += delta;
  27. i++;
  28.  
  29. if (Math.abs(delta) <= Math.abs(result)*EPSILON){
  30. //interrupts loop
  31. break;
  32.  
  33. }
  34.  
  35. }
  36.  
  37. return result; //replaceD :)
  38. }
  39.  
  40. public static void main(String[] args) {
  41. //modificated output
  42. System.out.println("sinh(0)=" + sinh(0.0));
  43. System.out.println("sinh(1)=" + sinh(1.0));
  44. System.out.println("sinh(-1)=" + sinh(-1.0));
  45. System.out.println("sinh(1000)=" + sinh(1000.0));
  46. //validation follows
  47. System.out.println();
  48. System.out.println("The following validates our results:");
  49. System.out.println("Validating the faCtorial method, inserting 5, result: "+ faCtorial(5));
  50. System.out.println("Value 1 must be: "+Math.sinh(0.0));
  51. System.out.println("Value 2 must be: "+Math.sinh(1.0));
  52. System.out.println("Value 3 must be: "+Math.sinh(-1.0));
  53. System.out.println("Value 4 must be: "+Math.sinh(1000.0));
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement