1

I have this equation in R.

f <- function(x) {first +second*x +third*x^2  +fourth*filter_factor - log(myBITRATE)}

where

first= -5.219078
second = 0.7613156
third = -0.01298033
fourth = -0.05218249
filter_factor = 1
myBITRATE = 184.47

Is there a way to find the roots of this equation?

I need a starting point for the newton-raphson method.

zinon
  • 4,427
  • 14
  • 70
  • 112

1 Answers1

2

Your function is a second order polynome with one variable, so you can do a trivial calculation:

delta = second^2 - 4*third*(first + fourth*filter_factor - log(myBITRATE))

Since your delta is strictly positive:

x1 = (- second - sqrt(delta))/(2*third)
x2 = (- second + sqrt(delta))/(2*third)

#> x1
#[1] 36.53336
#> f(x1)
#[1] 0
#> x2
#[1] 22.11812
#> f(x2)
#[1] 8.881784e-16
Colonel Beauvel
  • 30,423
  • 11
  • 47
  • 87
  • What about cases where delta has negative value? – zinon Sep 16 '15 at 12:01
  • I would ask you what do you expect when there is a negative value since there is no solution? a `NA`? Beware your question is unclear in what output you want (a list with potential solutions?) – Colonel Beauvel Sep 16 '15 at 12:03
  • OK, I got it. I have another question. What about my equation was `f <- function(x) {first +second*x +third*filter_factor - log(myBITRATE)}` Can you help me with this too? – zinon Sep 16 '15 at 12:21
  • I think I already answered the question ... I agree it's a site to provide help, leads but not to do all the homework :) You can adapt the formula depending of your coefficients: https://en.wikipedia.org/wiki/Quadratic_equation – Colonel Beauvel Sep 16 '15 at 12:23