DATA 605 FUNDAMENTALS OF COMPUTATIONAL MATHEMATICS

Discussion 13: Calculus Ch. 4 & 7

Kyle Gilde

11/19/2017

## Warning: package 'Deriv' was built under R version 3.3.3
##           installed_and_loaded.packages.
## prettydoc                           TRUE
## stats                               TRUE
## Deriv                               TRUE

Using R, provide the solution for any exercise in either Chapter 4 or Chapter 7 of the calculus textbook. If you are unsure of your solution, post your concerns.

Chapter 4.3

  1. Find the maximum product of two numbers (not necessarily integers) that have a sum of 100.
max_value <- 1000
min_value <- -max_value

fx <- function(x) {
    x * (100 - x)
}
fxprime <- Deriv(fx)
out_root <- uniroot(fxprime, c(min_value, max_value))

fx(out_root$root)
## [1] 2500
x <- seq(min_value, max_value)
plot(x, fx(x))
abline(out_root$root, out_root$f.root, col = "red")

  1. Find the minimum sum of two numbers whose product is 500.

\(\lim x \rightarrow 0^- f(x) = -\infty\)

max_value <- 100
min_value <- -max_value

fx <- function(x) {
    x + 500/x
}
fxprime <- Deriv(fx)
(out_root <- uniroot(fx, c(min_value, max_value)))
## Warning in uniroot(fx, c(min_value, max_value)): NA/Inf replaced by maximum
## positive value
## $root
## [1] -9.536737e-05
## 
## $f.root
## [1] -5242883
## 
## $iter
## [1] 22
## 
## $init.it
## [1] NA
## 
## $estim.prec
## [1] 9.536737e-05