ProGAL.math
Class Polynomial

java.lang.Object
  extended by ProGAL.math.Polynomial

public class Polynomial
extends java.lang.Object

A representation of a variable sized polynomial. To find the roots of the parabola f(x) = 2x^2 + 3x - 4, for instance, write Polynomial parabola = new Polynomial(new double[]{2,3,4}); double[] roots = parabola.calcRoots(); or simply double[] roots = Polynomial.calcRoots(2,3,4); Currently this only works for polynomials of degree 2 and 3.

Author:
rfonseca

Field Summary
 double[] parameters
           
 
Method Summary
 double[] calcRoots()
          Find the roots of the polynomial.
static double[] calcRoots(double[] parameters)
          Find the roots of the polynomial specified by the parameters.
static double[] calcRoots(double a, double b, double c)
          Find the roots of a second degree polynomial.
static double[] calcRoots(double a, double b, double c, double d)
          Find the roots of a third degree polynomial.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parameters

public final double[] parameters
Method Detail

calcRoots

public double[] calcRoots()
Find the roots of the polynomial. The imaginary part is not returned.

Returns:
an array containing the roots of the polynomial

calcRoots

public static double[] calcRoots(double[] parameters)
Find the roots of the polynomial specified by the parameters. The imaginary part is not returned.

Parameters:
parameters - an array representing the coefficents of the polynomial
Returns:
an array containing the roots of the polynomial

calcRoots

public static double[] calcRoots(double a,
                                 double b,
                                 double c)
Find the roots of a second degree polynomial. The length of the returned array depends on how many roots the quadratic equation has. In other words: The imaginary part is removed completely.

Parameters:
a - coefficient of the squared term
b - coefficient of the linear term
c - coefficient of the constant
Returns:
an array containing the roots of the polynomial

calcRoots

public static double[] calcRoots(double a,
                                 double b,
                                 double c,
                                 double d)
Find the roots of a third degree polynomial. The length of the returned array depends on how many roots the cubic equation has. In other words: The imaginary part is removed completely.

Parameters:
a - coefficient of the cubed term
b - coefficient of the squared term
c - coefficient of the linear term
d - coefficient of the constant term
Returns:
an array containing the roots of the polynomial