SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.analysis.function.polynomial.root
Class Quadratic

java.lang.Object
  extended by com.numericalmethod.suanshu.analysis.function.polynomial.root.Quadratic
All Implemented Interfaces:
Solver

public class Quadratic
extends java.lang.Object
implements Solver

This is a quadratic equation solver.

Solve

ax2 + bx + c = 0

The roots are:

 -b     SQRT(b2 - 4ac)
 -- ± ------------------
 2a           2a
 

See Also:
Wikipedia: Quadratic equation

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.numericalmethod.suanshu.analysis.function.polynomial.root.Solver
Solver.RootFindingException, Solver.Type
 
Constructor Summary
Quadratic()
          Construct a Solver instance to solve quadratic equations.
 
Method Summary
 NumberList solve(Polynomial polynomial)
          Solve ax2 + bx + c = 0
 Solver.Type type()
          Get the type of the solver.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Quadratic

public Quadratic()
Construct a Solver instance to solve quadratic equations.

Method Detail

type

public Solver.Type type()
Description copied from interface: Solver
Get the type of the solver.

Specified by:
type in interface Solver
Returns:
the solver type

solve

public NumberList solve(Polynomial polynomial)
Solve
ax2 + bx + c = 0

Specified by:
solve in interface Solver
Parameters:
polynomial - the quadratic polynomial to solve
Returns:
a list of all roots in Number
Throws:
java.lang.IllegalArgumentException - if the polynomial degree is not 2

SuanShu, a Java numerical and statistical library

Copyright © 2011 Numerical Method Inc. Ltd. All Rights Reserved.