com.softsynth.jmsl.util
Class Polynomial

java.lang.Object
  extended by com.softsynth.jmsl.util.Polynomial

public class Polynomial
extends java.lang.Object

Polynomial
Implement polynomial using MusicShape as coefficient holder. MusicShape has 1 dimension. Element index is power of X, value at a given index is coefficient.

Author:
Nick Didkovsky

Constructor Summary
Polynomial()
          create a polynomial with no terms
Polynomial(double c0)
          create a polynomial with one term of specified constant
Polynomial(double c1, double c0)
          create a polynomial with two terms with specified coefficients
Polynomial(double c2, double c1, double c0)
          create a polynomial with specified coefficients
Polynomial(double c3, double c2, double c1, double c0)
          create a polynomial with specified coefficients
Polynomial(double c4, double c3, double c2, double c1, double c0)
          create a polynomial with specified coefficients
Polynomial(double c5, double c4, double c3, double c2, double c1, double c0)
          create a polynomial with specified coefficients
 
Method Summary
 void addTerm(double coefficient, int power)
          Add the coefficient of given term to the specified coefficient.
 void appendTerm(double coefficient)
          Append a term with specified coefficient.
 double evaluate(double x)
          Evaluate this polynomial for x
 double get(int power)
           
 MusicShape getTerms()
           
static void main(java.lang.String[] args)
           
static Polynomial minus(Polynomial p1, Polynomial p2)
          Subtract polynomial from another.
static Polynomial mult(double scaler, Polynomial p1)
          Multiply a Polynomial by a scaler
static Polynomial mult(Polynomial p1, Polynomial p2)
          Multiply two Polynomials
static Polynomial plus(Polynomial p1, Polynomial p2)
          Add two polynomials together
 void setTerm(double coefficient, int power)
          Set the coefficient of given term
 int size()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Polynomial

public Polynomial()
create a polynomial with no terms


Polynomial

public Polynomial(double c0)
create a polynomial with one term of specified constant


Polynomial

public Polynomial(double c1,
                  double c0)
create a polynomial with two terms with specified coefficients


Polynomial

public Polynomial(double c2,
                  double c1,
                  double c0)
create a polynomial with specified coefficients


Polynomial

public Polynomial(double c3,
                  double c2,
                  double c1,
                  double c0)
create a polynomial with specified coefficients


Polynomial

public Polynomial(double c4,
                  double c3,
                  double c2,
                  double c1,
                  double c0)
create a polynomial with specified coefficients


Polynomial

public Polynomial(double c5,
                  double c4,
                  double c3,
                  double c2,
                  double c1,
                  double c0)
create a polynomial with specified coefficients

Method Detail

appendTerm

public void appendTerm(double coefficient)
Append a term with specified coefficient. Power will be next available order (ie if the polynomial is of order 2, appendTerm will supply the coefficient for x^3


setTerm

public void setTerm(double coefficient,
                    int power)
Set the coefficient of given term


addTerm

public void addTerm(double coefficient,
                    int power)
Add the coefficient of given term to the specified coefficient. ex. addTerm(3, 1) add 3x to a polynomial, addTerm(4, 3) adds 4x^3


get

public double get(int power)
Returns:
coefficient of nth term (first term=0)

size

public int size()

plus

public static Polynomial plus(Polynomial p1,
                              Polynomial p2)
Add two polynomials together

Returns:
new Polynomial that is the sum of p1 and p2

minus

public static Polynomial minus(Polynomial p1,
                               Polynomial p2)
Subtract polynomial from another. (First arg - Second arg)

Returns:
new Polynomial p1 - p2

mult

public static Polynomial mult(Polynomial p1,
                              Polynomial p2)
Multiply two Polynomials

Returns:
new Polynomial that is the product p1 * p2

mult

public static Polynomial mult(double scaler,
                              Polynomial p1)
Multiply a Polynomial by a scaler

Returns:
new Polynomial that is the product scaler * p

evaluate

public double evaluate(double x)
Evaluate this polynomial for x


getTerms

public MusicShape getTerms()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)