Nama : Sausan Shalihah Alfirdausi

NIM : 230605110064

Mata Kuliah : Kalkulus

Dosen Pengampu : Prof. Dr. Suhartono,M.Kom

Program Studi : Teknik Informatika

Universitas : Universitas Islam Negeri Malang

MEMBUAT GRAFIK TEMUAN NOL

Pada artikel kali ini Saya akan membuat tutorial untuk mendapatkan grafik fungsi setelah memasukkan fungsi f(x) dan nilai x nya dengan lima langkah.

Pertama kita perlu mengimpor (memuat) paket mosaicCalc. Paket ini menyediakan beberapa fungsi untuk analisis kalkulus.

library(mosaicCalc)
## Loading required package: mosaic
## Warning: package 'mosaic' was built under R version 4.3.2
## 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

Lalu yang kedua buatlah fungsi (f) yang merepresentasikan persamaan matematika 2x^2 - 2x - 2. Fungsi ini dibuat menggunakan fungsi makeFun dari paket mosaicCalc. Persamaan tersebut dinyatakan dalam bentuk formula R (~ adalah operator formula). Menampilkan isi dari objek fungsi f. Ini akan menunjukkan formula matematika yang telah diassign ke f.

f <- makeFun(2 * x^2 - 2*x - 2 ~ x)
f
## function (x) 
## 2 * x^2 - 2 * x - 2

Selanjutnya yang ketiga masukkan nilai fungsi f pada x=1, sesuai dengan persamaan yang didefinisikan.

f(1)
## [1] -2

Keempat, R akan menghitung titik-titik di mana fungsi f bernilai 0 (akar persamaan). Zeros adalah fungsi dari paket mosaicCalc yang digunakan untuk menghitung nol (akar) dari suatu fungsi pada rentang tertentu. Rentang di sini adalah x dari -5 hingga 5.

Zeros(f(x) - 0 ~ x, bounds(x=-5:5))
## # A tibble: 2 × 2
##        x     .output.
##    <dbl>        <dbl>
## 1 -0.618 0.0000000286
## 2  1.62  0.0000000286

Membuat plot dari fungsi f pada rentang x dari -5 hingga 5 menggunakan slice_plot. Selanjutnya, menambahkan garis horizontal pada nilai y=3 dengan warna pink menggunakan gf_hline. %>% adalah operator pipe yang digunakan untuk menyusun beberapa operasi secara berurutan.

slice_plot(f(x) ~ x, bounds(x=-5:5)) %>%
  gf_hline(yintercept = ~ 5, color="pink")