Learn R Programming

stokes (version 1.2-1)

inner: Inner product operator

Description

The inner product

Usage

inner(M)

Value

Returns a \(k\)-tensor, an inner product

Arguments

M

square matrix

Author

Robin K. S. Hankin

Details

The inner product of two vectors \(\mathbf{x}\) and \(\mathbf{y}\) is usually written \(\left\langle\mathbf{x},\mathbf{y}\right\rangle\) or \(\mathbf{x}\cdot\mathbf{y}\), but the most general form would be \(\mathbf{x}^TM\mathbf{y}\) where \(M\) is a matrix. Noting that inner products are multilinear, that is \(\left\langle\mathbf{x},a\mathbf{y}+b\mathbf{z}\right\rangle=a\left\langle\mathbf{x},\mathbf{y}\right\rangle+b\left\langle\mathbf{x},\mathbf{z}\right\rangle\) and \(\left\langle a\mathbf{x}+b\mathbf{y},\mathbf{z}\right\rangle=a\left\langle\mathbf{x},\mathbf{z}\right\rangle+b\left\langle\mathbf{y},\mathbf{z}\right\rangle\), we see that the inner product is indeed a multilinear map, that is, a tensor.

Given a square matrix \(M\), function inner(M) returns the \(2\)-form that maps \(\mathbf{x},\mathbf{y}\) to \(\mathbf{x}^TM\mathbf{y}\). Non-square matrices are effectively padded with zeros.

A short vignette is provided with the package: type vignette("inner") at the commandline.

See Also

kform

Examples

Run this code

inner(diag(7))
inner(matrix(1:9,3,3))

## Compare the following two:
Alt(inner(matrix(1:9,3,3)))      # An alternating k tensor
as.kform(inner(matrix(1:9,3,3))) # Same thing coerced to a kform

f <- as.function(inner(diag(7)))
X <- matrix(rnorm(14),ncol=2)  # random element of (R^7)^2
f(X) - sum(X[,1]*X[,2]) # zero to numerical precision

## verify positive-definiteness:
g <- as.function(inner(crossprod(matrix(rnorm(56),8,7))))
stopifnot(g(kronecker(rnorm(7),t(c(1,1))))>0)

Run the code above in your browser using DataLab