library(mosaicCalc)
## Loading required package: mosaic
## Registered S3 method overwritten by 'mosaic':
## method from
## fortify.SpatialPolygonsDataFrame ggplot2
##
## The 'mosaic' package masks several functions from core packages in order to add
## additional features. The original behavior of these functions should not be affected by this.
##
## Attaching package: 'mosaic'
## The following objects are masked from 'package:dplyr':
##
## count, do, tally
## The following object is masked from 'package:Matrix':
##
## mean
## The following object is masked from 'package:ggplot2':
##
## stat
## The following objects are masked from 'package:stats':
##
## binom.test, cor, cor.test, cov, fivenum, IQR, median, prop.test,
## quantile, sd, t.test, var
## The following objects are masked from 'package:base':
##
## max, mean, min, prod, range, sample, sum
## Loading required package: mosaicCore
##
## Attaching package: 'mosaicCore'
## The following objects are masked from 'package:dplyr':
##
## count, tally
##
## Attaching package: 'mosaicCalc'
## The following object is masked from 'package:stats':
##
## D
Optimasi merujuk pada proses pencarian nilai ekstremum (maksimum atau minimum) dari suatu fungsi dalam suatu domain tertentu. Tujuannya adalah untuk menemukan nilai terbaik dari suatu fungsi objektif.
Sebagai contoh, kita akan mencari nilai maksimum dan minimum dari fungsi yang sama yaitu
f <- function(x) { x^3 - 6*x^2 + 9*x - 4 }
x <- seq(-1, 4, length.out = 1000)
y <- f(x)
min_f_x <- x[which.min(y)]
min_f_y <- min(y)
max_f_x <- x[which.max(y)]
max_f_y <- max(y)
#Minimum
cat("Minimum:", min_f_x, "f(min) =", min_f_y, "\n")
## Minimum: -1 f(min) = -20
#Maksimum
cat("Maksimum:", max_f_x, "f(max) =", max_f_y, "\n")
## Maksimum: 4 f(max) = 0
#Graf
plot(x, y, type = "l", xlim = c(min_f_x - 1, 4), ylim = c(min_f_y - 2, max_f_y + 2))
points(min_f_x, min_f_y, col = "black", pch = 19)
points(max_f_x, max_f_y, col = "deeppink", pch = 19)
text(min_f_x, min_f_y - 1, "Min", col = "black")
text(max_f_x, max_f_y + 1, "Max", col = "deeppink")
Referensi: Kaplan, Daniel. 2022. MOSAIC Calculus. GitHub Pages. https://dtkaplan.github.io/MC2/