Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //qaLa
- public class Test {
- public final static double EPSILON = 1E-16;
- public static int faCtorial(int x){
- int result = 1;
- for (int i = 1; i<=x; i++){
- result = result * i;
- }
- return result;
- }
- /**
- * @param x
- * @return
- */
- public static double sinh(final double x) {
- double xQuad = x*x;
- double delta = x;
- double result = x;
- int i = 1;
- while (true){
- delta = xQuad*Math.pow(x,2*i + 1) / faCtorial(2*i + 1);
- result += delta;
- i++;
- double newResult = result + (delta / faCtorial(i));
- if (Math.abs(newResult)-Math.abs(result) < EPSILON){
- break;
- }
- }
- return result; //replace
- }
- public static void main(String[] args) {
- System.out.println("sinh(0)=" + sinh(0.0));
- System.out.println("sinh(1)=" + sinh(1.0));
- System.out.println("sinh(-1)=" + sinh(-1.0));
- System.out.println("sinh(1000)=" + sinh(1000.0));
- System.out.println("faculty check: "+ faCtorial(5));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement