Package com.softsynth.jmsl.util
Class Polynomial
java.lang.Object
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.
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
Constructors Constructor Description Polynomial()
create a polynomial with no termsPolynomial(double c0)
create a polynomial with one term of specified constantPolynomial(double c1, double c0)
create a polynomial with two terms with specified coefficientsPolynomial(double c2, double c1, double c0)
create a polynomial with specified coefficientsPolynomial(double c3, double c2, double c1, double c0)
create a polynomial with specified coefficientsPolynomial(double c4, double c3, double c2, double c1, double c0)
create a polynomial with specified coefficientsPolynomial(double c5, double c4, double c3, double c2, double c1, double c0)
create a polynomial with specified coefficients -
Method Summary
Modifier and Type Method Description 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 xdouble
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 scalerstatic Polynomial
mult(Polynomial p1, Polynomial p2)
Multiply two Polynomialsstatic Polynomial
plus(Polynomial p1, Polynomial p2)
Add two polynomials togethervoid
setTerm(double coefficient, int power)
Set the coefficient of given termint
size()
java.lang.String
toString()
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
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 Details
-
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
Add two polynomials together- Returns:
- new Polynomial that is the sum of p1 and p2
-
minus
Subtract polynomial from another. (First arg - Second arg)- Returns:
- new Polynomial p1 - p2
-
mult
Multiply two Polynomials- Returns:
- new Polynomial that is the product p1 * p2
-
mult
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
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
main
public static void main(java.lang.String[] args)
-