Chapter 17. User-Defined Math Functions


Chapter 17. User -Defined Math Functions

In the previous chapter, we covered the built-in math capability of Java. The intrinsic math capability of Java is similar to that provided by C and C++. Among the methods Java defines are those that compute trigonometric, natural logarithm, power, square root, and exponential functions. There are some holes in the intrinsic Java math functionality ”there are no hyperbolic trigonometric functions for instance, and there is nothing exotic such as methods to compute gamma or Bessel functions.

One of the great strengths of Java is that it is easily expandable. If the Java libraries don't provide certain functionality, it is a relatively simple matter to add that yourself. In this chapter, we will show you how to create user- defined math methods and how to package the methods so they are freely accessible anywhere on your computer. The basic process can be applied to any mathematical function. The examples in this chapter include creating logarithmic and hyperbolic trigonometric functions, but we will also write a method to compute a higher transcendental function, the gamma function.

The specific topics covered in this chapter are ”

  • Basic plan of attack

  • The Math2 class

  • Logarithm methods

  • Hyperbolic trigonometric methods

  • The gamma function

  • The final version of the Math2 class

  • Compiling the Math2 class

  • Using Math2 class methods

  • Comparing Java, C, and Fortran values



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