Learn R Programming

textir (version 1.8-8)

polynomial roots: Cubic and quadratic function solvers

Description

Find analytical roots to qubic and quadratic polynomials.

Usage

quadratic(b, c, quiet=FALSE, plot=FALSE)
cubic(a, b, c, quiet=FALSE, plot=FALSE)

Arguments

a,b,c
Polynomial function coefficients (MONIC FORM).
quiet
If false, the solution is printed to screen.
plot
If true, the function and real root(s) are plotted.

Value

  • A list with entries for the coefficients, roots, and solution characterization. In particular,
  • typeThe solution characterization: number of complex and real roots.
  • coefThe input coefficients.
  • rootsA vector of the equation roots.

    For the quadratic equation, if there are complex roots, roots[1] is the real part and roots[2] is the imaginary part (i.e., complex roots are roots[1] +- roots[2]*i). Otherwise, roots are (possibly identical) real roots.

    For the cubic equation, the first root roots[1] is always real. If there are complex roots, roots[2] is the real part and roots[3] is the imaginary part (i.e., complex roots are roots[2] +- roots[3]*i). Otherwise, roots[2:3] are (possibly identical) real roots.

Details

Finds roots to the cubic function $y = x^3 + ax^2 + bx + c$ or quadratic function $y = x^2 + bx + c$.

References

Abramovitz and Stegun, Handbook of Mathematical Functions, 1972.

See Also

'polyroot' for numerical solutions.

Examples

Run this code
quadratic(1,-2, plot=TRUE)
cubic(0,-15,-4, plot=TRUE)

Run the code above in your browser using DataLab