Chapter 5Solving systems of algebraic equations
Solving equations is central to numerical analysis, and R has numerous tools for doing so. We begin by extending our consideration of polynomials from the previous chapter.
5.1 Finding the zeros of a polynomial
The base installation of R has the function polyroot
to find the zeros of a real or complex polynomial, specified by the vector of its coefficients in ascending order. This function uses the algorithm of Jenkins and Traub (Jenkins and Traub (1972) TOMS Algorithm 419. Comm. ACM, 15, 9799). For example,
> polyroot(c(4,5,6)) [1] -0.4166667+0.7021791i -0.4166667-0.7021791i
Using the package PolynomF
, the code is a bit more cumbersome
> x = polynom() > (q = solve(4 + 5*x + 6*x^2)) # Solve ...
Get Using R for Numerical Analysis in Science and Engineering now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.