function_2D: Create a 2D function and returns the matrix

View source: R/function_2D.R

function_2DR Documentation

Create a 2D function and returns the matrix

Description

Create a matrix using vaector x, y and a function f(x,y) as inputs.
The returned matrix has elements positioned as would be expected an a euclidean co-ordinate grid.
This does NOT adhere to the positions built out of the outer(X, Y, FUN) function.

Usage

function_2D(X, Y, func)

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

Details

X and Y need to be numeric vectors.
func needs to be a function.
for plotting, please see *plot2D.mat()* and *plot2D()*

Value

The returned value is a matrix.
The no. of columns of the matrix is equal to the no. of X-values.
The no. of rows of the matrix are equal to the no. of Y-values.
The first element f(X[1], Y[1]) is located at the matrix position Z[length(Y), 1].
The element f(X[length(X)], Y[1]) is located at the matrix position Z[length(Y), length(X)].
The element f(X[1], Y[length(Y)]) is located at the matrix position Z[1, 1].
The element f(X[length(X)], Y[length(Y)]) is located at the matrix position Z[1, length(X)].

Author(s)

Chitran Ghosal

Examples

#define the x-axis
X <- seq(0, 10, by = 0.01)
Y <- seq(0, 16, by = 0.01)

#define the function
patt <- function(x, y){
  return(exp(-0.2*x - 0.1*y)*sin(3*x)*cos(4*y))
}

#build the Z matrix
Z <- function_2D(X, Y, patt)

#plot the matrix
plot2D.mat(X, Y, Z)

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