Matkul : Kalkulus, Dosen Pengampu : Prof. Dr. SUHARTONO, M.Kom


4.1.1 From Equations to Zeros of Functions

Salah satu cara untuk memecahkan masalah adalah dengan menemukan kebalikan dari fungsi f, tetapi menemukan kebalikan dari fungsi f bisa sangat sulit dan berlebihan. Sebaliknya, masalah dapat ditangani dengan menemukan nol dari fungsi f.

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 <- makeFun(sin(x^2)*cos(sqrt(x^4 + 2 )-x^1) - x + 3 ~ x)
slice_plot(g(x) ~ x, domain(x = -3:4)) %>%
  gf_hline(yintercept  = 0, color = "red") %>%
   gf_vline(xintercept  = 0, color = "red")

Fungsi ini akan mencoba menemukan jumlah solusi yang tak terbatas.

library(mosaic)
findZeros(g(x) ~ x, xlim = range(-2, 3))
## Warning in findZeros(g(x) ~ x, xlim = range(-2, 3)): No zeros found. You might
## try modifying your search window or increasing npts.
## numeric(0)
findZeros( sin(x) - 0.35 ~ x, xlim=range(-20,20) )
##           x
## 1  -12.2088
## 2   -9.7823
## 3   -5.9256
## 4   -3.4991
## 5    0.3576
## 6    2.7840
## 7    6.6407
## 8    9.0672
## 9   12.9239
## 10  15.3504
findZeros(g(x) ~ x, xlim = range(-1000,  1000))
##        x
## 1 3.0601
g <- makeFun(4 + exp(k*t) - 2^(b*t) ~ b, k=0.00035, t=1)
findZeros( g(b) ~ b , xlim=range(-1000, 1000) )
##       b
## 1 2.322
findZeros( g(b, t=2) ~ b, xlim=range(-1000,1000) )
##        b
## 1 1.1611
findZeros( sin(cos(x^2) - x) -x - 0.5 ~ x, xlim=range(-10,10))
##        x
## 1 0.2098
findZeros( 3*exp(-t/5)*sin(pi*t) ~ t, xlim=range(1,10))
##    t
## 1  0
## 2  1
## 3  2
## 4  3
## 5  4
## 6  5
## 7  6
## 8  7
## 9  8
## 10 9
findZeros( 3*x^2 + 7*x - 10 ~ x, xlim=range(-100,100))
##         x
## 1 -3.3334
## 2  1.0000
findZeros(2*x^3 - 4*x^2 - 3*x - 10 ~ x, xlim=c(-10,10))
##        x
## 1 3.0363
findZeros( 7*x^4 -2*x^3 - 4*x^2 - 3*x - 10 ~ x, xlim=c(-10,10))
##         x
## 1 -1.0628
## 2  1.4123
findZeros( 6*x^5-7*x^4 -2*x^3 - 4*x^2 - 3*x - 10 ~ x, xlim=c(-10,10))
##        x
## 1 1.8012

Daftar Pustaka : https://dtkaplan.github.io/RforCalculus/