Learn R Programming

vectorialcalculus (version 1.0.5)

surface_integral_z: Surface integral over a graph z = g(x, y)

Description

Computes numeric approximations of surface integrals over a surface given in graph form z = g(x, y) on a rectangular domain in the x-y plane.

Usage

surface_integral_z(
  gfun,
  xlim,
  ylim,
  nx = 160,
  ny = 160,
  scalar_phi = NULL,
  vector_F = NULL,
  orientation = c("up", "down"),
  plot = TRUE,
  title = "Surface integral over z = g(x,y)"
)

Value

A list with components:

  • area_density_integral: numeric scalar with the value of the scalar surface integral (or NA if scalar_phi is not supplied).

  • flux_integral: numeric scalar with the value of the flux integral (or NA if vector_F is not supplied).

  • plot: a plotly surface object if plot = TRUE, otherwise NULL.

  • grids: list with matrices and grid information, including X, Y, Z, partial derivatives, and weights.

  • fields: list with the scalar and/or flux integrand evaluated on the grid.

Arguments

gfun

Function of two variables function(x, y) returning the height z = g(x, y) of the surface.

xlim

Numeric vector of length 2 giving the range for x, c(x_min, x_max) with x_max > x_min.

ylim

Numeric vector of length 2 giving the range for y, c(y_min, y_max) with y_max > y_min.

nx

Integer, number of grid points in the x direction (recommended: at least 20).

ny

Integer, number of grid points in the y direction (recommended: at least 20).

scalar_phi

Optional scalar field function(x, y, z). If provided, the function computes the scalar surface integral of scalar_phi over the surface.

vector_F

Optional vector field function(x, y, z) that returns a numeric vector of length 3 c(Fx, Fy, Fz). If provided, the function computes the flux integral of vector_F across the oriented surface.

orientation

Character string indicating the orientation of the normal vector, either "up" or "down". This affects the sign of the flux integral.

plot

Logical. If TRUE, returns a plotly surface plot colored by the available integrand (scalar field times area density or flux density).

title

Character string used as the base title for the plot.

Details

Two types of integrals can be computed:

  1. A scalar surface integral of the form Integral_S phi dS, where phi(x, y, z) is a scalar field evaluated on the surface.

  2. A flux (vector surface integral) of the form Integral_S F dot n dS, where F(x, y, z) is a vector field and n is the chosen unit normal direction.

The surface is parametrized by (x, y) -> (x, y, g(x, y)) over a rectangular domain given by xlim and ylim. Partial derivatives of g with respect to x and y are approximated by finite differences on a uniform grid, and the integrals are computed using a composite trapezoid rule on that grid.

Examples

Run this code
if (interactive()) {
# Surface z = x^2 + y^2 on [-1,1] x [-1,1]
gfun <- function(x, y) x^2 + y^2

# Scalar field phi(x,y,z) = 1 (surface area of the patch)
phi <- function(x, y, z) 1

# Vector field F = (0, 0, 1), flux through the surface
Fvec <- function(x, y, z) c(0, 0, 1)

res <- surface_integral_z(
  gfun,
  xlim = c(-1, 1),
  ylim = c(-1, 1),
  nx = 60, ny = 60,
  scalar_phi = phi,
  vector_F = Fvec,
  orientation = "up",
  plot = FALSE
)
res$area_density_integral
res$flux_integral
}

Run the code above in your browser using DataLab