Calculate hyperbolic tangent in Java

Description

The following code shows how to calculate hyperbolic tangent.

Example


//www  .  jav a 2  s . c  o m
public strictfp class Main {
  public static void main(String[] args) {
    // Obtain angle in degrees from user
    double degs = 20d;
    // Convert degrees to radian
    double rads = Math.toRadians(degs);
    
        // Calculate hyperbolic sine
    double sinHA = (Math.exp(rads) - Math.exp(-rads)) / 2;
    System.out.println("Hyperbolic sine = " + sinHA);

    // Calculate Hyperbolic cosine
    double cosHA = (Math.exp(rads) + Math.exp(-rads)) / 2;
    System.out.println("Hyperbolic cosine = " + cosHA);

    // Calculate hyperbolic tangent
    double tanHA = sinHA / cosHA;
    System.out.println("Hyperbolic tangent = " + tanHA);
    
    
  }
}




















Home »
  Java Tutorial »
    Development »




Java Algorithms
Java Clipboard
Java Compiler
Java Desktop
Java Virtual Machine
Java Math
OS
Random
Java Robot
Java RuntimeMXBean
Java Timer
Java UUID
Java Internationalization