Exploring an Inequality
Introduction
I have attempted to give a mathematical proof of the following inequality,
Exploring
Define function
Method 1
Calculate values of the above function for some given values of
R code:
library(dplyr)
f <- function(a, b, c, d)
{a/(1+b) + b/(1+c) + c/(1+d) + d/(1+a)
}
n <- 10
df <-
expand.grid(a = seq(0, 1, length.out = n),
b = seq(0, 1, length.out = n),
c = seq(0, 1, length.out = n),
d = seq(0, 1, length.out = n)) %>%
mutate(the_f_value = f(a, b, c, d))
(summary(df$the_f_value))
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.000 1.212 1.442 1.399 1.632 2.000
NB: To save running time, I set
Method 2
Use base::optim
to find the maximum of the function
g <- function(x)
{x[1]/(1 + x[2]) + x[2]/(1 + x[3]) + x[3]/(1 + x[4]) + x[4]/(1 + x[1])
}
(re <- optim(par = c(0, 0, 0, 0), fn = g, method = "L-BFGS-B",
lower = rep(0, 4), upper = rep(1, 4),
control = list(fnscale = -1)))
## $par
## [1] 1 1 1 1
##
## $value
## [1] 2
##
## $counts
## function gradient
## 2 2
##
## $convergence
## [1] 0
##
## $message
## [1] "CONVERGENCE: NORM OF PROJECTED GRADIENT <= PGTOL"
NB:
- To use
base::optim
, we must define in the way likeg
in the above. - In the
par
, we set an initial value. control = list(fnscale = -1)
is used because we want to find the maximum rather than the minimum.