R/QUADP.R

Defines functions QUADM QUADP

# solves quadratic equation given by y = a + b*x + c*x^2
# Based on MAESTRA equivalent (B. Medlyn)

# - larger root
QUADP <- function(A,B,C){
  
  if((B^2 - 4*A*C) < 0){
    warning("IMAGINARY ROOTS IN QUADRATIC")
    return(0)
  }
  
  if(identical(A,0)){
    if(identical(B,0)){
      return(0)
    } else {
      return(-C/B)
    }
  } else {
   return((- B + sqrt(B^2 - 4*A*C)) / (2*A))
  }
  
}

# - smaller root
QUADM <- function(A,B,C){
  
  if((B^2 - 4*A*C) < 0){
    warning("IMAGINARY ROOTS IN QUADRATIC")
    return(0)
  }
  
  if(identical(A,0)){
    if(identical(B,0)){
      return(0)
    } else {
      return(-C/B)
    }
  } else {
    return((- B - sqrt(B^2 - 4*A*C)) / (2*A))
  }
  
}

Try the plantecophys package in your browser

Any scripts or data that you put into this service are public.

plantecophys documentation built on April 1, 2021, 1:06 a.m.