cubic {RConics}R Documentation

Roots of the cubic equation.

Description

Return the roots of a cubic equation of the form ax^3 + bx^2 + cx + d=0.

Usage

cubic(p)

Arguments

p

a (4 \times 1) vector of the four parameters (a, b, c, d) of the cubic equation.

Value

A vector corresponding to the roots of the cubic equation.

Source

W. H. Press, S.A. Teukolsky, W.T. Vetterling, B.P. Flannery (2007). NUMERICAL RECIPES - the art of scientific computing. Cambridge, University Press, chap 5.6, p. 227-229.

Examples

# cubic equation x^3 - 6x^2 + 11x - 6 = 0
# parameter
b <- c(1,-6, 11, -6)

# roots
x0 <- cubic(b)

# plot
x <- seq(0,4, by=0.001)
y <- b[1]*x^3 + b[2]*x^2 + b[3]*x + b[4]

# plot
plot(x,y,type="l")
abline(h=0,v=0)
points(cbind(x0,c(0,0,0)), pch=20,col="red",cex=1.8)

[Package RConics version 1.1.1 Index]