Name: Achmad Fahry Baihaki

NIM: 2206065110100

Institute: Maulana Malik Ibrahim Islamic State University of Malang

Departement: Computer Science


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

After we’ve learn about plotting functions of one variable. This time we’ll learn about plotting functions of two variables using contour plot function.

Syntax to use contour plot is contour_plot(). We need to list the two variables on the right of the + sign and give it a range for each of the variables. For example:

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

We can assign range using direct range syntax. For example:

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

If we want to see the function as a surface, plotted in 3 dimensions. We can get the computer to display a prespective 3-dimensional plot by using the interactive plot function.

Syntax to use interactive plot is interactive_plot(). For example:

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

We can mousing around the plot to see the details. It’s interactive.

To read the quantitive values from a surface plot is very hard — the countour plots are much more useful for that. People seem to have a strong intuition about shapes of surfaces. Being able to translate in your mind from contours to surfaces (vice versa) is a valuable skill.

To create a function that you can evaluate numerically, construct the function with makeFun(). Example:

g <- makeFun(
  sin(2*pi*t/10)*exp(-.2*x) ~ t & x)
contour_plot(
  g(t, x) ~ t + x,  
  domain(t=0:20, x=0:10))

Input values to the arguments. Make sure to name the arguments explicitly. Like this example below:

g(t = 8, x = 9)
## [1] -0.1572086