Bagian 7 Derivatif dan diferensiasi Seperti halnya semua perhitungan, operator untuk mengambil turunan, mengambil input dan menghasilkan output. Faktanya, dibandingkan dengan banyak operator, cukup sederhana: hanya membutuhkan satu input.D()D()

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

7.1 Rumus dan Perbedaan Numerik Ketika ekspresi relatif sederhana dan terdiri dari fungsi matematika dasar, akan sering mengembalikan fungsi yang berisi rumus matematika. Misalnya, dalam contoh di atasD()

g
## function (x) 
## 2 * x
h <- D(sin(abs(x - 3) ) ~ x)
h
## function (x) 
## {
##     .e1 <- x - 3
##     cos(abs(.e1)) * sign(.e1)
## }

7.2 Parameter Simbolik Anda dapat menyertakan parameter simbolik dalam ekspresi yang sedang dimasukkan, misalnya:D()

s2 <- D(A  * sin(2 * pi * t / P) + C ~ t)

Fungsi yang dibuat akan berfungsi seperti fungsi matematika lainnya, tetapi Anda perlu menentukan nilai numerik untuk parameter simbolik ketika Anda mengevaluasi fungsi:s2()

s2
## function (t, A, C, P) 
## (2 * A * pi * cos((2 * pi * t)/P))/P
s2( t=3, A=2, P=10, C=4 )
## [1] -0.3883222
slice_plot(s2(t, A=2, P=10, C=4) ~ t, 
           domain(t=range(0,20)))

7.3 Derivatif Parsial Derivatif dihitung olehturunan parsial. Artinya, mereka adalah turunan di mana variabel di sisi kanan ofis berubah dan semua variabel lainnya dianggap konstan.D( )~

7.3.1 Turunan kedua Turunan kedua hanyalah turunan dari turunan. Anda dapat menggunakan operator dua kali untuk menemukan turunan kedua, seperti ini.D( )

df <- D(sin(x) ~ x)
ddf <- D(df(x) ~ x)
another.ddf <- D(sin(x) ~ x & x)

Formulir untuk turunan orde kedua dan lebih tinggi ini juga memberikan perhitungan yang lebih akurat.