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
Forward Differentiation merupakan metode numerik untuk menghitung turunan suatu fungsi numerik dengan menggunakan pendekatan beda maju (forward difference). Pendekatan ini memanfaatkan nilai-nilai fungsi di titik x dan x+h untuk mendekati nilai turunan.
Rumus forward difference untuk mengaproksimasi turunan adalah: f ′(x)≈ f(x+h)−f(x)/h
Di mana h adalah suatu nilai kecil yang mendekati nol dan f(x+h) adalah nilai fungsi di titik x+h. Semakin kecil nilai h, semakin dekat nilai aproksimasi turunan dengan nilai sebenarnya.
Mari kita buat contoh sederhana menggunakan Python untuk menghitung turunan dari fungsi f(x)=x^2 menggunakan metode forward differentiation:
# Fungsi
f <- function(x) {
return(x^2 - 8)
}
# 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 = "blue", xlab = "x", ylab = "f(x)", main = "Grafik f(x) = x^2 - 8")
abline(v = x, h = f(x), col = "red", lty = 2, lwd = 2)
Dalam contoh ini, mendefinisikan fungsi f(x)=x^2−8 dan fungsi untuk menghitung turunannya dengan metode forward differentiation. Kemudian kita menghitung turunan pada titik x=3 dengan h=0.01 dan menampilkan grafik fungsi tersebut beserta garis singgung pada titik x.
Hasilnya akan menampilkan grafik fungsi f(x)=x^2−8 (garis biru) dan garis singgung pada titik x (garis putus-putus merah). Di grafik, garis singgung menunjukkan kemiringan fungsi pada titik x yang dihitung menggunakan forward differentiation.