Nama : Sausan Shalihah Alfirdausi

NIM : 230605110064

Mata Kuliah : Kalkulus

Dosen Pengampu : Prof. Dr. Suhartono,M.Kom

Program Studi : Teknik Informatika

Universitas : Universitas Islam Negeri Malang

library(mosaicCalc)
## Loading required package: mosaic
## Warning: package 'mosaic' was built under R version 4.3.2
## 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
 f <- function(x) {
  return(x^2 - x + 9)
}

# Nilai x di mana kita ingin menghitung turunan
x <- 3

# Nilai h
h <- 0.01

# Menghitung turunan menggunakan forward differentiation
forward_diff <- (f(x + h) - f(x)) / h

# Membuat array x untuk plot grafik
x_values <- seq(-10, 10, by = 0.1)
y_values <- f(x_values)

# Plot grafik fungsi dan garis singgung pada titik x
plot(x_values, y_values, type = "l", col = "pink", xlab = "x", ylab = "f(x)", main = "Grafik f(x) = x^2 - x + 9")
abline(v = x, h = f(x), col = "skyblue", lty = 2, lwd = 2)

Berikut adalah penjelasan perbaris dari kode R yang diberikan:

f <- function(x) {…}: Mendefinisikan fungsi kuadratik f(x) = x^2 - x + 9.

x <- 3: Menginisialisasi nilai x di mana kita ingin menghitung turunan dan garis singgung.

h <- 0.01: Menginisialisasi nilai h yang digunakan untuk menghitung turunan menggunakan metode diferensiasi maju (forward differentiation).

forward_diff <- (f(x + h) - f(x)) / h: Menghitung turunan pertama menggunakan metode diferensiasi maju (forward differentiation) pada titik x dengan nilai h.

x_values <- seq(-10, 10, by = 0.1): Membuat array nilai x dari -10 hingga 10 dengan interval 0.1 untuk digunakan dalam plot.

y_values <- f(x_values): Menghitung nilai fungsi f(x) pada setiap nilai x untuk digunakan dalam plot.

plot(x_values, y_values, type = “l”, col = “pink”, xlab = “x”, ylab = “f(x)”, main = “Grafik f(x) = x^2 - x + 9”): Membuat plot dari nilai-nilai fungsi f(x) menggunakan garis (type = “l”) dengan warna merah muda. Menambahkan label sumbu x (xlab), label sumbu y (ylab), dan judul plot (main).

abline(v = x, h = f(x), col = “skyblue”, lty = 2, lwd = 2): Menambahkan garis singgung pada titik x ke dalam plot dengan garis putus-putus (lty = 2), ketebalan garis (lwd = 2), dan warna biru langit. Garis singgung ini dihitung menggunakan nilai fungsi dan nilai turunan pada titik x.

Kode ini menghasilkan plot yang menunjukkan grafik fungsi kuadratik serta garis singgung pada titik x. Metode diferensiasi maju digunakan untuk menghitung turunan pertama fungsi.

Daftar Pustaka https://www.mosaic-web.org/MOSAIC-Calculus/Modeling/06-operations.html