KickJava   Java API By Example, From Geeks To Geeks.

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


1 package JSci.maths.analysis;
2
3 /**
4 * The power function.
5 * For polynomials or integer exponents use the classes in JSci.maths.polynomials.
6 * @version 1.1
7 * @author Mark Hale
8 */

9 public class Power extends RealFunction {
10         private final double A, n, k;
11         /**
12         * Constructs a power function of the form <code>x</code>.
13         */

14         public Power() {
15         this(1.0, 0.0, 1.0);
16         }
17         /**
18         * Constructs a power function of the form <code>Ax<sup>n</sup></code>.
19         */

20         public Power(double A, double n) {
21         this(A, 0.0, n);
22         }
23         /**
24         * Constructs a power function of the form <code>A(x+k)<sup>n</sup></code>.
25         */

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