knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The stokes
package provides functionality for working with the
exterior calculus. It includes tensor products and wedge products and
a variety of use-cases. The canonical reference would be Spivak (see
references). A detailed vignette is provided in the package.
The package deals with $k$-tensors and $k$-forms. A $k$-tensor is a multilinear map $S\colon V^k\longrightarrow\mathbb{R}$, where $V=\mathbb{R}^n$ is considered as a vector space. Given two $k$-tensors $S,T$ the package can calculate their outer product $S\otimes T$ using natural R idiom (see below and the vignette for details).
A $k$-form is an alternating $k$-tensor, that is a $k$-tensor $\omega$ with the property that linear dependence of $x_1,\ldots,x_n$ implies that $\omega\left(x_1,\ldots,x_n\right)=0$. Given $k$-forms $\omega,\eta$, the package provides R idiom for calculating their wedge product $\omega\wedge\eta$.
You can install the released version of stokes
from
CRAN with:
# install.packages("stokes") # uncomment this to install the package library("stokes") set.seed(0)
stokes
package in useThe package has two main classes of objects, kform
and ktensor
.
In the package, we can create a $k$-tensor by supplying function
as.ktensor()
a matrix of indices and a vector of coefficients, for
example:
jj <- as.ktensor(rbind(1:3,2:4),1:2) jj
Above, object jj
is equal to $dx_1\otimes dx_2\otimes dx_3 +
2dx_2\otimes dx_3\otimes dx_4$ (see Spivak, p76 for details).
We can coerce tensors to a function and then evaluate it:
KT <- as.ktensor(cbind(1:4,2:5),1:4) f <- as.function(KT) E <- matrix(rnorm(10),5,2) f(E)
Tensor products are implemented:
KT %X% KT
Above we see ${\mathrm KT}\otimes{\mathrm KT}$.
An alternating form (or $k$-form) is an antisymmetric $k$-tensor; the
package can convert a general $k$-tensor to alternating form using the
Alt()
function:
Alt(KT)
However, the package provides a bespoke and efficient representation
for $k$-forms as objects with class kform
. Such objects may be
created using the as.kform()
function:
M <- matrix(c(4,2,3,1,2,4),2,3,byrow=TRUE) M KF <- as.kform(M,c(1,5)) KF
Above, we see that KF
is equal to $dx_2\wedge dx_3\wedge dx_4 +
5dx_1\wedge dx_2\wedge dx_4$. We may coerce KF
to functional form:
f <- as.function(KF) E <- matrix(rnorm(12),4,3) f(E)
Above, we evaluate KF
at a point in $\left({\mathbb R^4}\right)^3$
[the three columns of matrix E
are each interpreted as vectors in
${\mathbb R}^4$].
The wedge product of two $k$-forms is implemented as ^
or
wedge()
:
KF2 <- kform_general(6:9,2,1:6) KF2 KF ^ KF2
The package can accommodate a number of results from the exterior calculus such as elementary forms:
dx <- as.kform(1) dy <- as.kform(2) dz <- as.kform(3) dx ^ dy ^ dz # element of volume
A number of useful functions from the exterior calculus are provided, such as the gradient of a scalar function:
grad(1:6)
The package takes the leg-work out of the exterior calculus:
grad(1:4) ^ grad(1:6)
The most concise reference is
But a more leisurely book would be
For more detail, see the package vignette
vignette("stokes")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.