Transcendental Math FunctionsJava provides two transcendental math functions. The first raises Euler's constant to the power of the value of an argument. The second returns the natural logarithm of an argument.
exp() returns the value e a , Euler's number raised to the power of the input argument. If the input argument is NaN , the return value is NaN . If the input argument is negative infinity, zero is returned. If the input argument is positive infinity, positive infinity is returned. log() returns the natural logarithm of the input argument. If the argument is less than zero or NaN , the return value is NaN . Example: Using log() and exp()Another way to compute the coefficient of viscosity for a pure gas species is by using the Blottner curve fit expression. 2 The general form of the expression is shown in Eq. (16.7). Equation 16.7
Eq. (16.7) is also a good way to demonstrate the use of the log() and exp() methods . The LogDemo class uses log() and exp() to compute the coefficient of viscosity of diatomic nitrogen at a temperature of 1000 K using the Blottner relation. Compare the result using this method with the result from the "Using pow() and sqrt() Methods" example. public class LogDemo { public static void main(String args[]) { // Define some variables and some constants double A = 0.0268142; double B = 0.3177838; double C = -11.3155513; double T = 1000.0; double eta, grp; // Use the log() and exp() methods to compute // the coefficient of viscosity for diatomic // nitrogen at 1000 K. grp = A*Math.log(T)*Math.log(T) + B*Math.log(T) + C; eta = Math.exp(grp); System.out.println("Viscosity is "+eta+ " gm/cm-sec"); } } Output ” Viscosity is 3.93321517e-04 gm/cm-sec |