NIM: 230605110047
Lembaga: Universitas Islam Negeri Maulana Malik Ibrahim
Fakultas: Sains dan Teknologi
Jurusan: Teknik Informatika
Kelas: B
library(mosaicCalc)
## Warning: package 'mosaicCalc' was built under R version 4.3.2
## 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
Turunan/ derivatif dari fungsi mengukur tingkat di mana nilai fungsi berubah saat inputnya berubah. Perubahan nilai fungsi tergantung pada arah perubahan nilai variabel independen.
Diferensiasi adalah proses menemukan turunan dari fungsi yang dapat dibedakan. Perbedaan keduanya adalah derivatif mengacu pada tingkat perubahan fungsi sedangkan diferensiasi adalah proses menemukan turunan dari suatu fungsi.
Dalam pemrograman R, turunan dari suatu fungsi dapat digunakan menghitung dan fungsi. Ini digunakan untuk menghitung turunan dari ekspresi sederhana. deriv() D()
Syntax
deriv(expr,name)
D(expr,name)
Output yang dihasilkan adalah fungsi. Fungsi akan mencantumkan sebagai argumen semua variabel yang terkandung dalam ekpresi input. Lalu, mengevaluasi fungsi output untuk nilai numerik tertentu untuk menemukan nilai fungsi turunan.
Kita bisa menggunakan fungsi D() untuk menghitung diferensiasi sebuah fungsi.
Misalnya
g <- D(x^7 ~ x)
g(2)
## [1] 448
g(7.6)
## [1] 1348900
my_function <- function(x) {
return (7 * x^5)
}
my_function(2)
## [1] 224
g<-D(my_function(x)~x)
g(20)
## [1] 5600000
s2 <- D(A * sin(2 * pi * t / P) + C ~ t)
s2( t=5, A=4, P=8, C=2 )
## [1] -2.221441
slice_plot(s2(t, A=6, P=30, C=100) ~ t,
domain(t=range(0,20)))
Contoh derivative / turunan lainnya adalah:
f = expression(x^3 + 5*x + 3)
cat("Menggunakan fungsi deriv() :\n")
## Menggunakan fungsi deriv() :
print(deriv(f, "x"))
## expression({
## .value <- x^3 + 5 * x + 3
## .grad <- array(0, c(length(.value), 1L), list(NULL, c("x")))
## .grad[, "x"] <- 3 * x^2 + 5
## attr(.value, "gradient") <- .grad
## .value
## })
cat("\nMenggunakan fungsi D() :\n")
##
## Menggunakan fungsi D() :
print(D(f, 'x'))
## 3 * x^2 + 5
rena_deriv <- deriv(~ x^3 + 2 * x, "x")
x <- 7
eval(rena_deriv)
## [1] 357
## attr(,"gradient")
## x
## [1,] 149
**Fungsi Eval telah mengembalikan hasil yaitu (7^3 + 2*7)**