Learn R Programming

CVXR (version 1.0-14)

log,Expression-method: Logarithms

Description

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)\).

Usage

# S4 method for Expression
log(x, base = base::exp(1))

# S4 method for Expression log10(x)

# S4 method for Expression log2(x)

# S4 method for Expression log1p(x)

Value

An Expression representing the exponentiated input.

Arguments

x

An Expression.

base

(Optional) A positive number that is the base with respect to which the logarithm is computed. Defaults to \(e\).

Examples

Run this code
# 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

Run the code above in your browser using DataLab