log function

Logarithms

Logarithms

The elementwise logarithm. log computes the logarithm, by default the natural logarithm, log10 computes the common (i.e., base 10) logarithm, and log2 computes the binary (i.e., base 2) logarithms. The general form log(x, base) computes logarithms with base base. log1p computes elementwise the function log(1+x)\log(1+x). methods

## S4 method for signature 'Expression' log(x, base = base::exp(1)) ## S4 method for signature 'Expression' log10(x) ## S4 method for signature 'Expression' log2(x) ## S4 method for signature 'Expression' log1p(x)

Arguments

  • x: An Expression .
  • base: (Optional) A positive number that is the base with respect to which the logarithm is computed. Defaults to ee.

Returns

An Expression representing the exponentiated input.

Examples

# Log in objective x <- Variable(2) obj <- Maximize(sum(log(x))) constr <- list(x <= matrix(c(1, exp(1)))) prob <- Problem(obj, constr) result <- solve(prob) result$value result$getValue(x) # Log in constraint obj <- Minimize(sum(x)) constr <- list(log2(x) >= 0, x <= matrix(c(1,1))) prob <- Problem(obj, constr) result <- solve(prob) result$value result$getValue(x) # Index into log obj <- Maximize(log10(x)[2]) constr <- list(x <= matrix(c(1, exp(1)))) prob <- Problem(obj, constr) result <- solve(prob) result$value # Scalar log obj <- Maximize(log1p(x[2])) constr <- list(x <= matrix(c(1, exp(1)))) prob <- Problem(obj, constr) result <- solve(prob) result$value
  • Maintainer: Anqi Fu
  • License: Apache License 2.0 | file LICENSE
  • Last published: 2024-11-07