D()mengambil input dan menghasilkan output
Input: ekspresi menggunakan ~notasi. Contoh: x^2~xatau sin(x^2)~xatauy*cos(x)~y Di sebelah kiri ~adalah ekspresi matematis, ditulis dalam notasi R yang benar, yang akan mengevaluasi ke angka ketika nilai numerik tersedia untuk semua besaran yang direferensikan.
Di sebelah kanan ~adalah variabel sehubungan dengan mana turunannya akan diambil. Output yang dihasilkan adalahD() sebuah fungsi. Anda kemudian dapat mengevaluasi fungsi output untuk nilai numerik tertentu dari argumen untuk menemukan nilai fungsi turunan.
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
g <- D(x^2 ~ x)
g(1)
## [1] 2
rumus selisih
D() akan mengembalikan fungsi yang didasarkan pada perasaan numerik ke turunan
h <- D(sin(abs(x - 3) ) ~ x)
h
## function (x)
## {
## .e1 <- x - 3
## cos(abs(.e1)) * sign(.e1)
## }
parameter simbolik
library(mosaicCalc)
s2 <- D(A * sin(2 * pi * t / P) + C ~ t)
s2( t=3, A=8, P=12, C=8 )
## [1] 2.56481e-16
slice_plot(s2(t, A=8, P=12, C=8) ~ t,
domain(t=range(0,20)))
Turunan kedua parsial menggunakan D() operator dua kali untuk menemukan turunan kedua.
df <- D(sin(x) ~ x)
ddf <- D(df(x) ~ x)
findiff <- function(f, x, h, method=NULL){
if(is.null(method)){
warning("please select a method")
}else{
if(method == "forward"){
return((f(x+h)-f(x))/h)
}else if(method=="backward"){
return((f(x)-f(x-h))/h)
}else if(method=="central"){
return((f(x+h)-f(x-h))/(2*h))
}else{
warning("you can use method: forward, bacward, or central")
}
}
}
LATIHAN
findiff(function(x)
3*(x^8) + 5*(x^6) + x*4-x + 11, x=4, h=0.05,
method="central")
## [1] 424385.1
findiff(function(x)
3*x + 3*(x^2) + x , x=3, h=0.05,
method="central")
## [1] 22
findiff(function(x)
3*(x^4) + 2*(x^2) + 2*x, x=1, h=0.05,
method="central")
## [1] 18.03
REFERENSI
https://dtkaplan.github.io/RforCalculus/derivatives-and-differentiation.html#partial-derivatives