KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > maths > polynomials > RealMonomialBasis


1 package JSci.maths.polynomials;
2
3 import JSci.maths.fields.Field;
4
5 import java.lang.UnsupportedOperationException JavaDoc;
6
7 /**
8  *
9  * @author b.dietrich
10  */

11 public class RealMonomialBasis implements PolynomialBasis {
12     private RealPolynomial[] _basis;
13     private int _dim;
14
15     /** Creates a new instance of RealMonomialBasis */
16     public RealMonomialBasis( int dim ) {
17         _dim = dim;
18         _basis = new RealPolynomial[dim];
19     }
20
21     /**
22      *
23      * @param k
24      *
25      * @return a basis vector
26      */

27     public Polynomial getBasisVector( int k ) {
28         if ( k >= _dim ) {
29             throw new ArrayIndexOutOfBoundsException JavaDoc();
30         } else {
31                 double[] db = new double[_dim];
32                 db[k] = 1.0;
33                 _basis[k] = new RealPolynomial( db );
34             return _basis[k];
35         }
36     }
37
38     /**
39      *
40      * @return the dimension of this basis
41      */

42     public int dimension() {
43         return _dim;
44     }
45
46     /**
47      *
48      */

49     public Field.Member[] getSamplingPoints() {
50         throw new UnsupportedOperationException JavaDoc("Not implemented.");
51     }
52
53     /**
54      *
55      * @param coeff
56      *
57      */

58     public Polynomial superposition(Field.Member[] coeff) {
59         return superposition( RealPolynomialRing.toDouble( coeff ) );
60     }
61
62     /**
63      *
64      * @param d
65      */

66     public RealPolynomial superposition( double[] d ) {
67         if ( d == null ) {
68             throw new NullPointerException JavaDoc();
69         }
70         if ( d.length != _dim ) {
71             throw new IllegalArgumentException JavaDoc( "Dimension of basis is " + _dim + ". Got "
72                                                 + d.length + " coefficients" );
73         }
74
75         return new RealPolynomial( d );
76     }
77 }
78
Popular Tags