plot2D: Accepts a 2D function f(x,y) along with x and y vectors and...

View source: R/plot2D.R

plot2DR Documentation

Accepts a 2D function f(x,y) along with x and y vectors and plots it

Description

Accepts a function f(x,y) along with vectors, x and y and plots it in grayscale

Usage

function(X, Y, func, pl = T, gray.dens = 10^5, x.lab = NULL, y.lab = NULL)
function(X, Y, func, pl = T)
function(X, Y, func, pl = F)

Arguments

X

Describes the (numeric) vector in the X direction

Y

Describes the (numeric) vector in the Y direction

func

Describes the function used to calculate the Z return matrix

pl

Boolean bit used to specify whether plotting is needed or not.
Default set to TRUE.

gray.dens

Numeric value used to describe the grayscale density.
Default value set to 10^5.

x.lab

Sets the label of the x-axis.
Character vector of length 1 needed.
Default value set to NULL.

y.lab

Sets the label of the y-axis.
Character vector of length 1 needed.
Default value set to NULL.

Details

X and Y need to be numeric vectors.
func needs to be a function.
for directly plotting a matrix, please see *plot2D.mat()*.
gray.dens has to be a whole number.
x.lab and y.lab have to be a single valued character vectors, if not NULL.

Value

The returned value is always a numeric matrix.
If pl is set to TRUE, a plot is also produced.
The plot is always returned with an asp = 1.0.

Author(s)

Chitran Ghosal

Examples

#define the function
f_test <- function(x, y){
  return(sin(5 * x) * cos(5 * y) + cos(x^2 + y^2))
}

#define the x-axis
x_seq <- seq(-10, 10, by = 0.01)

#define the y-axis
y_seq <- seq(-7, 7, by = 0.01)

#plot the function and get the matrix Z
Z = plot2D(X = x_seq, Y = y_seq, func = f_test, x.lab = 'X', y.lab = 'Y')


Chitran1987/StatsChitran documentation built on Feb. 23, 2025, 8:30 p.m.