Matkul : Kalkulus, Dosen Pengampu : Prof. Dr. SUHARTONO, M.Kom
Contoh fungsi kalkulus 1 variabel
luas_persegi <- function(sisi) {
sisi^2
}
Mengisi variabel funsgi
test1_variabel = luas_persegi(5)
test1_variabel
## [1] 25
Contoh fungsi kalukulus 2 variabel
luas_segitiga <- function(alas, tinggi) {
alas * tinggi / 2
}
Mengisi variabel fungsi
luas_segitiga(6,12)
## [1] 36
Contoh fungsi kalkulus 3 variabel
volume_balok <- function(panjang, lebar, tinggi) {
panjang * lebar * tinggi
}
Mengisi variabel fungsi
volume_balok(3,4,6)
## [1] 72
Mencoba Fungsi Eksponensial dengan grafik Menggunakan Library Mosaic
Fungsi awal :
drug_remaining <- function(dose, duration, time_constant) {
dose * exp(- duration / time_constant)
}
Coba fungsi
drug_remaining(dose = 100, duration = 10, time_constant = 4)
## [1] 8.2085
Visualisasi grafik
library(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
t = 0:30
plotFun (drug_remaining(dose=100, time_constant = 4, duration =t) ~ t, t.lim = range(0,30))
Daftar pustaka : https://dtkaplan.github.io/RforCalculus/representing-mathematical-functions.html#r-language-functions