** DATA_605_Discussion_13_Optimization_Chapter_4.3_Problem_3. **
http://rpubs.com/danthonn/384363
** Optimization **
if (!require(Deriv)) install.packages("Deriv")
## Loading required package: Deriv
## Warning: package 'Deriv' was built under R version 3.3.3
library(Deriv)
if (!require(stats)) install.packages("stats")
library(stats)
Chapter 4.3
3). Find the maximum product of two numbers (not necessarily integers) that have a sum of 100.
Reference: see Example 102 in Chapter 4.3 of the calculus text(page 173)
# setup range to evalate the function (by testing)
max <- 2000
min <- -max
# setup equations:
# function:
# if
# a + b = 100
# then
# b = 100 - a
# and
# a * b = a * (100 - a)
funct_a <- function(a) {
a * (100 - a)
}
# set derivative of function b
funct_a_der <- Deriv(funct_a)
# find root equation for derivative of b
root <- uniroot(funct_a_der, c(min, max))
#find the root
funct_a(root$root)
## [1] 2500
## [1] 2500
# plot the results
b <- seq(min, max)
plot(b, funct_a(b))
abline(root$root, root$f.root, col = "blue")
** END **