# Rで指数・対数　Rで数学の色々をいじってみる

> options(digits=22)
> exp(1)
[1] 2.718281828459045090796
> options(digits=7)


n<-1:100
plot((1+1/n)^n)
n<-1:1000
plot(exp(n*log((n+1)/n)))

> log(exp(1))
[1] 1
> log(1)
[1] 0
> log(1:10)
[1] 0.0000000 0.6931472 1.0986123 1.3862944 1.6094379 1.7917595
[7] 1.9459101 2.0794415 2.1972246 2.3025851
> log(1:10,10)
[1] 0.0000000 0.3010300 0.4771213 0.6020600 0.6989700 0.7781513
[7] 0.8450980 0.9030900 0.9542425 1.0000000
> log(1:10)/log(1:10,10)
[1]      NaN 2.302585 2.302585 2.302585 2.302585 2.302585
[7] 2.302585 2.302585 2.302585 2.302585

• exp(),log()関数のバリエーション
log(x, base = exp(1))
logb(x, base = exp(1))
log10(x)
log2(x)
log1p(x)
exp(x)
expm1(x)
help(exp)

log computes logarithms, by default natural logarithms, log10 computes common (i.e., base 10) logarithms, and log2 computes binary (i.e., base 2) logarithms. The general form log(x, base) computes logarithms with base base.

log1p(x) computes log(1+x) accurately also for |x| << 1 (and less accurately when x is approximately -1).

exp computes the exponential function.

expm1(x) computes exp(x) - 1 accurately also for |x| << 1.