Dosen Pengampu : Prof. Dr.Suhartono, M.Kom
Lembaga : Universitas Islam Negeri Maulana Malik Ibrahim Malang
Fakultas : Sains dan Teknologi
Jurusan : Teknik Informatika
Kelas : (C) Kalkulus
NIM : 230605110080
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
## The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
## which was just loaded, will retire in October 2023.
## Please refer to R-spatial evolution reports for details, especially
## https://r-spatial.org/r/2023/05/15/evolution4.html.
## It may be desirable to make the sf package available;
## package maintainers should consider adding sf to Suggests:.
## The sp package is now running under evolution status 2
## (status 2 uses the sf package in place of rgdal)
##
## Attaching package: 'mosaicCalc'
## The following object is masked from 'package:stats':
##
## D
library(ggplot2)
Definisi: Optimasi tanpa kendala tidak memiliki batasan, yang berarti dapat mencari nilai ekstrem dari fungsi objektif tanpa memperhatikan batasan apa pun.
Pendekatan: Metode Newton-Raphson, metode gradien konjugat, atau metode quasi-Newton adalah beberapa contoh pendekatan yang dapat digunakan dalam optimasi tanpa kendala.
Contoh :
DENGAN NILAI MINIMUM
Minimalkan fungsi : f(x) = (x−3)^2 + 5
Dalam masalah ini, mencari nilai x yang akan memberikan nilai minimum dari fungsi kuadrat f(x).
Variabel Keputusan:
x: Variabel yang ingin dioptimalkan. Fungsi Objektif: Minimize f(x) = (x−3)^2 + 5
# Install dan memuat paket ggplot2
install.packages("ggplot2")
## Warning: package 'ggplot2' is in use and will not be installed
library(ggplot2)
# Fungsi Objektif
f <- function(x) {
return((x - 3)^2 + 5)
}
# Generate data untuk plot
x_values <- seq(-5, 10, by = 0.1)
y_values <- f(x_values)
# Data Frame
df <- data.frame(x = x_values, y = y_values)
# Plot
ggplot(df, aes(x, y)) +
geom_line(color = "blue") +
geom_point(color = "red", size = 3) +
labs(title = "Optimasi Tanpa Kendala",
x = "Nilai x",
y = "Nilai f(x)") +
theme_minimal()
Kode di atas membuat grafik dari fungsi f(x) dan menunjukkan titik minimum. Pada contoh ini, karena mencari minimum dapat dilihat bahwa titik minimum terjadi di sekitar x =3 (yang merupakan nilai yang diharapkan, karena fungsi dibentuk sebagai (x−3)^2 +5.
# Install dan memuat paket ggplot2 jika belum terinstal
# install.packages("ggplot2")
library(ggplot2)
# Fungsi yang akan diplot
f <- function(x) (x - 3)^2 + 5
# Membuat data frame untuk x dan f(x)
data <- data.frame(x = seq(-2, 8, by = 0.1), y = f(seq(-2, 8, by = 0.1)))
# Membuat plot dengan ggplot2
ggplot(data, aes(x, y)) +
geom_line(color = "blue", size = 1) +
geom_point(color = "red", size = 2) +
labs(title = "Grafik Fungsi f(x) = (x-3)^2 + 5",
x = "x",
y = "f(x)")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
DENGAN NILAI MAKSIMUM
Optimasi tanpa kendala dengan nilai maksimum adalah suatu masalah di mana mencari nilai maksimum dari suatu fungsi objektif tanpa adanya batasan atau kendala. Dalam kasus ini, kita hanya perlu mencari nilai maksimum dari fungsi tersebut tanpa memikirkan batasan yang membatasi solusi. Contoh sederhana dari optimasi tanpa kendala dengan nilai maksimum adalah mencari nilai maksimum dari fungsi kuadratik. Misalkan kita memiliki fungsi:
f(x)= −x^2 + 4x + 5
Untuk menemukan nilai maksimum dari fungsi ini, dapat menggunakan kalkulus diferensial dengan mengambil turunan pertama dan mengaturnya sama dengan nol:
f′(x) = −2x + 4
Setelah mengaturnya sama dengan nol, kita dapat menyelesaikan untuk x:
−2x + 4 = 0 x = 2
Sehingga nilai maksimum fungsi f(x) terjadi saat x=2. Kita dapat memasukkan nilai ini kembali ke dalam fungsi f(x) untuk mendapatkan nilai maksimum:
f(2) = −(2)^2 + 4(2) + 5 = 9
Jadi, nilai maksimum dari fungsi f(x) tanpa adanya batasan adalah 9, dan x=2 adalah titik di mana nilai maksimum tersebut dicapai.
# Install paket ggplot2 jika belum terinstall
# install.packages("ggplot2")
# Memuat paket ggplot2
library(ggplot2)
# Membuat fungsi
f <- function(x) -x^2 + 4*x + 5
# Membuat data frame untuk nilai x dan f(x)
data <- data.frame(x = seq(-1, 5, by = 0.1), y = f(seq(-1, 5, by = 0.1)))
# Membuat plot dengan ggplot2
plot <- ggplot(data, aes(x, y)) +
geom_line(color = "blue") +
geom_point(color = "red", size = 2) +
labs(title = "Grafik fungsi f(x) = -x^2 + 4x + 5",
x = "Nilai x",
y = "f(x)")
# Menampilkan plot
print(plot)