Universitas Islam Negeri Maulana Malik Ibrahim Malang

Fakultas Sains dan Teknologi

NAMA : ZULFA ULINNUHA

NIM : 220605110075

KELAS : TI-C

JURUSAN : TEKNIK INFORMATIKA

Dosen Pengampu : Prof.Dr. Suhartono M.Kom

Matkul : Kalkulus

Bab 2 Fungsi Grafik

2.1 Grafik Fungsi Matematika

Fungsi adalah transformasi dari input ke output. Fungsi digunakan untuk menyatakan hubungan antar besaran.

Dalam banyak notasi matematika, fungsi dinamai seperti: f, g, y dan input dilambangkan sebagai x. Huruf lain digunakan untuk mewakili parameter. Misalnya, adalah umum untuk menulis persamaan garis dengan cara ini: y + mx = b

Dalam merencanakan suatu fungsi, kita perlu menentukan:

Apa fungsinya. Ini biasanya diberikan oleh ekspresi, misalnya m * x + b atau A * x ^ 2 atau sin(2 * t)

Apa inputnya. Ingat, tidak ada alasan untuk berasumsi bahwa x selalu menjadi input.

Berapa kisaran input untuk membuat plot berakhir. Anggap ini sebagai batas sumbu horizontal di mana Anda ingin membuat plot.

Nilai parameter apa pun. Ingat, notasi m * x + b ~ x tidak hanya melibatkan input variabel x tetapi juga dua besaran lain, m dan b. Untuk membuat plot fungsi, Anda perlu memilih nilai spesifik untuk m dan b dan memberi tahu komputer nilai tersebut.

Ada tiga fungsi grafik di {mosaicCalc} yang yang dapat digunakan untuk membuat grafik fungsi, dan melapisi plot tersebut dengan grafik fungsi atau data lain, yaitu:

slice_plot()
contour_plot()
interactive_plot()
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
slice_plot( sqrt(t) * cos(7 * t) ~ t, domain(t = range(0, 5) ))

library(mosaicCalc)
m = 1
b = 2
slice_plot(m * x^3 + b ~ x, domain(x = range(-10, 10)))

perubahan dari kode program bisa dilakukan dengan merubah nilai variabel m, variabel m bisa diisi dengan nol, maka bisa menentukan grafik tersebut lurus atau stabil.

library(mosaicCalc)
m = 1
b = 20
slice_plot(m * x + b ~ x, domain(x = range(-10, 10)))

library(mosaicCalc)
m = -3
b = -2
slice_plot(m * x + b ~ x, domain(x = range(0, 10)))

library(mosaicCalc)
g  <- makeFun(2*x^2 - 5*x + 2 ~ x)
slice_plot(g(x) ~ x , domain(x = range(-2, 2)))

library(mosaicCalc)
A = 100
slice_plot( A * x ^ 2 ~ x, domain(x = range(-2, 3)))

library(mosaicCalc)
A = 8
slice_plot( A * x ^ 2 ~ x, domain(x = range(0, 3)), color ="pink" )

library(mosaicCalc)
slice_plot( cos(t) ~ t, domain(t = range(0,4*pi) ))

library(mosaicCalc)
contour_plot(
  sqrt( (v-3)^2 + 2*(w-4)^2 ) ~ v & w,
  domain(v=0:6, w=0:6))

library(mosaicCalc)
contour_plot(
  sin(2*pi*t/10)*exp(-.2*x) ~ t & x, 
  domain(t = range(0,20), x = range(0,10)))

diplot dalam 3 dimensi. Kita dapat menampilkan plot perspektif 3 dimensi dengan menggunakan fungsi interactive_plot(). Contoh:

interactive_plot(
   sin(2*pi*t/10)*exp(-.5*x) ~ t & x, 
   domain(t = 0:20, x = 0:10))

2.2 Membuat Scatterplot

File yang digunakan disimpan sebagai spreadsheet di Internet. Biasanya ada banyak variabel dalam spreadsheet; setiap variabel disimpan sebagai satu kolom. (Baris adalah “instance”, kadang-kadang disebut “titik data”.)

Untuk membaca data ke dalam R, Anda perlu mengetahui nama dan lokasi file. Seringkali lokasi adalah alamat di Internet.

Housing = read.csv("http://www.mosaic-web.org/go/datasets/Income-Housing.csv")

Grafik dibangun berlapis-lapis. Jika Anda ingin memplot fungsi matematika di atas data, Anda harus menggunakan fungsi plot untuk membuat layer lain. Kemudian, untuk menampilkan dua lapisan dalam plot yang sama, hubungkan dengan %>%simbol (disebut “pipa”). Perhatikan bahwa tidak pernah%>% bisa pergi di awal baris baru.

Di sini, akan dicoba mengambil data “Perumahan Pendapatan.csv”, yang terletak di “http://www.mosaic-web.org/go/datasets/Income-Housing.csv”. File ini memberikan informasi dari survei tentang kondisi perumahan untuk orang-orang dalam kelompok pendapatan yang berbeda di AS. Berikut adalah cara membacanya menjadi R:

Housing = read.csv("http://www.mosaic-web.org/go/datasets/Income-Housing.csv")

Ada dua hal penting yang perlu diperhatikan dari pernyataan di atas. Pertama, fungsi read.csv() mengembalikan nilai yang disimpan dalam objek yang disebut housing. Kedua, nama “http://www.mosaic-web.org/go/datasets/Income-Housing.csv” diapit oleh tanda kutip. Setelah data dibaca, Anda dapat melihat data hanya dengan mengetikkan nama objek (tanpa tanda kutip!) yang menyimpan data. Contohnya:

Housing
##   Income IncomePercentile CrimeProblem AbandonedBuildings IncompleteBathroom
## 1   3914                5         39.6               12.6                2.6
## 2  10817               15         32.4               10.0                3.3
## 3  21097               30         26.7                7.1                2.3
## 4  34548               50         23.9                4.1                2.1
## 5  51941               70         21.4                2.3                2.4
## 6  72079               90         19.9                1.2                2.0
##   NoCentralHeat ExposedWires AirConditioning TwoBathrooms MotorVehicle
## 1          32.3          5.5            52.3         13.9         57.3
## 2          34.7          5.0            55.4         16.9         82.1
## 3          28.1          2.4            61.7         24.8         91.7
## 4          21.4          2.1            69.8         39.6         97.0
## 5          14.9          1.4            73.9         51.2         98.0
## 6           9.6          1.0            76.7         73.2         99.0
##   TwoVehicles ClothesWasher ClothesDryer Dishwasher Telephone
## 1        17.3          57.8         37.5       16.5      68.7
## 2        34.3          61.4         38.0       16.0      79.7
## 3        56.4          78.6         62.0       25.8      90.8
## 4        75.3          84.4         75.2       41.6      96.5
## 5        86.6          92.8         88.9       58.2      98.3
## 6        92.9          97.1         95.6       79.7      99.5
##   DoctorVisitsUnder7 DoctorVisits7To18 NoDoctorVisitUnder7 NoDoctorVisit7To18
## 1                3.6               2.6                13.7               31.2
## 2                3.7               2.6                14.9               32.0
## 3                3.6               2.1                13.8               31.4
## 4                4.0               2.3                10.4               27.3
## 5                4.0               2.5                 7.7               23.9
## 6                4.7               3.1                 5.3               17.5

Semua variabel dalam kumpulan data akan ditampilkan. Dapat juga melihat nama semua variabel dalam format yang lebih ringkas dengan names(). Contoh:

names(Housing)
##  [1] "Income"              "IncomePercentile"    "CrimeProblem"       
##  [4] "AbandonedBuildings"  "IncompleteBathroom"  "NoCentralHeat"      
##  [7] "ExposedWires"        "AirConditioning"     "TwoBathrooms"       
## [10] "MotorVehicle"        "TwoVehicles"         "ClothesWasher"      
## [13] "ClothesDryer"        "Dishwasher"          "Telephone"          
## [16] "DoctorVisitsUnder7"  "DoctorVisits7To18"   "NoDoctorVisitUnder7"
## [19] "NoDoctorVisit7To18"

Dapat juga mengakses satu variabel dengan cara ketikkan nama seluruh variabel kemudian diikuti dengan data variabel dan dipisahkan oleh tanda $. Contoh:

Housing$AirConditioning
## [1] 52.3 55.4 61.7 69.8 73.9 76.7
library(mosaicCalc)
gf_point(CrimeProblem ~ Income, data = Housing )

gf_point(CrimeProblem ~ Income, data = Housing) %>% 
  slice_plot(40 - Income / 2000 ~ Income, color = "blue") %>%
  gf_lims(x = range(0,100000), y=range(0,50))

library(mosaicCalc)
gf_point(CrimeProblem ~ Income, data = Housing )

gf_point(CrimeProblem ~ Income, data = Housing) %>% 
  slice_plot(40 - Income / 2000 ~ Income, color = "blue") %>%
  gf_lims(x = range(0,100000), y=range(0,50))

library(mosaicCalc)
contour_plot(sin(2*pi*t/10) ~ t & x, 
  domain(t = range(0,20), x = range(0,10)))
## Warning in contour_plot(sin(2 * pi * t/10) ~ t & x, domain(t = range(0, : No
## dependence of function on y variable. Contour labels may be misplaced.

library(mosaicCalc)
contour_plot(sin(4*pi*t/32)*exp(-.4*x) ~ t & x, 
  domain(t = range(0,15), x = range(0,10)))

gf_point(ClothesDryer ~ ClothesDryer, data = Housing )

library(mosaicCalc)
Housing[1:3,1:2]
##   Income IncomePercentile
## 1   3914                5
## 2  10817               15
## 3  21097               30
library(mosaicCalc)
gf_point(CrimeProblem ~ Income, data=Housing ) %>%
  slice_plot(45 - Income/2500 ~ Income, color = "yellow")


DAFTAR PUSTAKA

https://dtkaplan.github.io/RforCalculus/index.html?fbclid=IwAR1d_WcAeawvUaBnLKlkRoO2sV4b-6nRX0eNR3DT457DKN7NJV8NV0giSLo