Power and Square Root Methods


Power and Square Root Methods

The power and square root methods are used to raise the value of one argument to the power of a second. The sqrt(double a) method described later in this chapter is equivalent to the method pow(double a, 0.5).


   public  static  double  pow(double  a,  double  b)
 
   public  static  double  sqrt(double  value)

pow() returns the first argument raised to the power of the second argument, a b . There are some special cases if one or both of the arguments is infinity or NaN . In these cases, the return value will be either infinity or NaN . You can also pass integer arguments to this method, as the integers will be automatically cast into double values.

sqrt() returns the square root of the input argument. If the argument is less than zero, NaN is returned. You can pass integer values to the sqrt() method as they will be automatically cast into double values.

Example: Using the pow() and sqrt() Methods

The coefficient of viscosity relates a velocity gradient to the shear stress the velocity gradient will generate. It is an important quantity when performing viscous flow calculations. For a pure gas species, the coefficient of viscosity is given by Eq. (16.5).

Equation 16.5

graphics/16equ05.gif


In Eq. (16.5), M is the molar mass of the gas species in gm / mole and T is the temperature in K. The graphics/16inl01.gif quantity is the reduced collision integral for the gas species. There are many ways to obtain values for the collision integral. For diatomic nitrogen, you can use the curve fit relation in Eq. (16.6). 1

Equation 16.6

graphics/16equ06.gif


The PowDemo class uses the pow() and abs() methods to compute the coefficient of viscosity for diatomic nitrogen at a temperature of 1000 K using Eq. (16.5) and Eq. (16.6). It also makes use of the log() method that will be described later in this chapter.

 public class PowDemo {   public static void main(String args[]) {     //  Define some variables and some constants     double M = 28.0134;     double T = 1000.0;     double Omega22, eta, grp;     //  Use the pow() and sqrt() methods to compute     //  the coefficient of viscosity for diatomic     //  nitrogen at 1000 K.     grp = -0.0203*Math.log(T) + 0.0683;     Omega22 = 19.0158*Math.pow(T,grp);     eta = 2.6693e-5*Math.sqrt(M*T)/Omega22;     System.out.println("Viscosity is " + eta +                        " gm/cm-sec");   } } 

Output ”

 Viscosity is 3.86142846e-4 gm/cm-sec 


Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net