Documentation of 'edu.rit.numeric.Quadratic' Java class
Quadratic
edu.rit.numeric

Class Quadratic



  • public class Quadratic
    extends java.lang.Object
    Class Quadratic solves for the real roots of a quadratic equation with real coefficients. The quadratic equation is of the form

    ax2 + bx + c = 0

    To solve a quadratic equation, construct an instance of class Quadratic; call the Quadratic object's solve() method, passing in the coefficients a, b, and c; and obtain the roots from the Quadratic object's fields. The number of (real) roots, either 0 or 2, is stored in field nRoots. If there are no roots, fields x1 and x2 are set to NaN. If there are two roots, they are stored in fields x1 and x2 in descending order.

    The same Quadratic object may be used to solve several quadratic equations. Each time the solve() method is called, the solution is stored in the Quadratic object's fields.

    The formulas for the roots of a quadratic equation come from:

    E. Weisstein. "Quadratic equation." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/QuadraticEquation.html

    • Field Summary

      Fields 
      Modifier and Type Field and Description
      int nRoots
      The number of real roots.
      double x1
      The first real root.
      double x2
      The second real root.
    • Constructor Summary

      Constructors 
      Constructor and Description
      Quadratic()
      Construct a new Quadratic object.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      static void main(java.lang.String[] args)
      Unit test main program.
      void solve(double a, double b, double c)
      Solve the quadratic equation with the given coefficients.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • nRoots

        public int nRoots
        The number of real roots.
      • x1

        public double x1
        The first real root.
      • x2

        public double x2
        The second real root.
    • Constructor Detail

      • Quadratic

        public Quadratic()
        Construct a new Quadratic object.
    • Method Detail

      • solve

        public void solve(double a,
                          double b,
                          double c)
        Solve the quadratic equation with the given coefficients. The results are stored in this Quadratic object's fields.
        Parameters:
        a - Coefficient of x2.
        b - Coefficient of x.
        c - Constant coefficient.
        Throws:
        DomainException - (unchecked exception) Thrown if a is 0; in other words, the coefficients do not represent a quadratic equation.
      • main

        public static void main(java.lang.String[] args)
                         throws java.lang.Exception
        Unit test main program.

        Usage: java edu.rit.numeric.Quadratic a b c

        Throws:
        java.lang.Exception

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.