cubic | R Documentation |
Return the roots of a cubic equation of the form ax^3 + bx^2 + cx + d=0.
cubic(p)
p |
a (4 \times 1) vector of the four parameters (a, b, c, d) of the cubic equation. |
A vector corresponding to the roots of the cubic equation.
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.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.