KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > maths > analysis > Exponential


1 package JSci.maths.analysis;
2
3 /**
4 * The exponential function.
5 * @version 1.1
6 * @author Mark Hale
7 */

8 public class Exponential extends RealFunction {
9         private final double A, w, n, k;
10         /**
11         * Constructs an exponential function of the form <code>exp(x)</code>.
12         */

13         public Exponential() {
14         this(1.0, 1.0, 0.0, 1.0);
15         }
16         /**
17         * Constructs an exponential function of the form <code>A exp(w(x+k))</code>.
18         */

19         public Exponential(double A, double w, double k) {
20         this(A, w, k, 1.0);
21         }
22         /**
23         * Constructs an exponential function of the form <code>A exp(w(x+k)<sup>n</sup>)</code>.
24     * Constructor to create Gaussian functions.
25         */

26         public Exponential(double A, double w, double k, double n) {
27                 this.A = A;
28                 this.w = w;
29                 this.k = k;
30                 this.n = n;
31         }
32         public double map(double x) {
33         x += k;
34         if(n == 1.0)
35             x = x;
36         else if(n == 2.0)
37             x *= x;
38         else
39             x = Math.pow(x, n);
40                 return A*Math.exp(w*x);
41         }
42         public RealFunction differentiate() {
43         RealFunction diff = new Exponential(A*w, w, k, n);
44         if(n != 1.0)
45             diff = new Power(n, k, n-1).multiply(diff);
46                 return diff;
47         }
48 }
49
Popular Tags