func_2_arr: Converts a 2D function into an array

View source: R/func_2_arr.R

func_2_arrR Documentation

Converts a 2D function into an array

Description

Converts a 2D function, f:\mathbb{R}^2 \to \mathbb{R}^1, of the form f(x,y) to a rank-3, 3-slice array T_{m,n,p}.
Please see details.

Usage

func_2_arr(func, X, Y)

Arguments

func

Describes the function f(x,y).
Has to be an R function

X

The X-vector over which the function should be evaluated.
The X and Y vectors form the X-Y grid over which the function is evaluated.

Y

The Y-vector over which the function should be evaluated.
The X and Y vectors form the X-Y grid over which the function is evaluated.

Details

The returned array, T_{m,n,p}, will be a 3-slice array, i.e. p \in \{1, 2, 3\}.
T_{m,n,1} is the data matrix for f(x,y).
T_{m,n,2} and T_{m,n,3} are the X-matrix and the Y-matrix respectively.
For clearer understanding please see image.
array.png

Value

The returned value is an R array, (T_{ijk})_{m \times n \times p},.
Here m and n are the length of the Y vector and X vector respectively while p = 3. Please see image above.

Author(s)

Chitran Ghosal

See Also

img_2_arr, plot2D.arr

Examples

###build the function
sines <- function(X, Y){
  w1 <- 2*X+3*Y
  w2 <- -3*X + Y
  return(sin(w1) + sin(w2))
}

###call the function
arr <- func_2_arr(func = sines, X = seq(-10,10, by=0.05), Y = seq(-7, 7, by = 0.05))
###plot the array
plot2D.arr(arr)

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