Ed Baker FLS ARCS

Picture of Ed Baker.

Interdisciplinary researcher using sensor networks and acoustics to monitor biodiversity and environments.

GitHub | CV | Media | Social

Latest publications

All publications

Google Scholar

Co-authorship Cloud

Latest blog posts

All blog posts

Talks

All talks

Notes

All notes

Some thoughts on

Inverting a polynomial using R

R code to numerically find the inverse of a polynomial.

# Define a polynomial function to invert
pn <- function(x) {
  return(3*x^3 + 2*x^2)
}

# Generic invert() function
invert = function(fn, interval = NULL, ...){
  Vectorize(function(y){
    uniroot(function(x){fn(x)-y}, interval, ...)$root
  })
}

# Inversion function specific to pn()
pn.inverse <- invert(pn, interval = c(-10, 10))

# Find the inverse for a specific value
pn.inverse(4)