cubic: Roots of the cubic equation.

Description Usage Arguments Value References Examples

View source: R/RConics.R

Description

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

Usage

1
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.

References

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# 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)

RConics documentation built on May 30, 2017, 5:22 a.m.