QMan5
QMan5

Reputation: 779

Given an x and polynomial equation, is there way to get the y value using r?

If I have a equation like 10 + x^2 + x^3 + x^4 = y and an x value like 2. Is there way to plug this into r so it would solve for y? It sounds trivial but eventually I would like to solve for x using polynomials that higher degrees like 30. Anyone know of a possible way to do this in r but without plugging in the x value manually?

Please note: I'm trying to solve for y given a specific x value.

Upvotes: 0

Views: 813

Answers (1)

Roland
Roland

Reputation: 132651

You can easily write your own function:

p <- function(x, coefs) c(cbind(1, poly(x, degree = length(coefs) - 1, 
                            raw = TRUE, simple = TRUE)) %*% coefs)
p(2, c(10, 0, 1, 1, 1))
#[1] 38

Use rep if you need many coefficients of 1.

Upvotes: 1

Related Questions