solution.basis: Calculate the basis for the solution space of a system of...

View source: R/transformSimplex.R

solution.basisR Documentation

Calculate the basis for the solution space of a system of linear equations

Description

Given a set of linear equality constraints, determine a translation and a basis for its solution space.

Usage

solution.basis(constr)

Arguments

constr

Linear equality constraints

Details

For a system of linear equations, Ax = b, the solution space is given by

x = A'b + (I - A' A)

where A' is the Moore-Penrose pseudoinverse of A. The QR decomposition of I - A'A enables us to determine the dimension of the solution space and derive a basis for that space.

Value

A list, consisting of

translate

A point in the solution space

basis

A basis rooted in that point

Author(s)

Gert van Valkenhoef

See Also

createTransform

Examples

# A 3-dimensional original space
n <- 3

# x_1 + x_2 + x_3 = 1
eq.constr <- list(constr = t(rep(1, n)), dir = '=', rhs = 1)
basis <- solution.basis(eq.constr)
stopifnot(ncol(basis$basis) == 2) # Dimension reduced to 2
y <- rbind(rnorm(100, 0, 100), rnorm(100, 0, 100))
x <- basis$basis %*% y + basis$translate
stopifnot(all.equal(apply(x, 2, sum), rep(1, 100)))

# 2 x_2 = x_1; 2 x_3 = x_2
eq.constr <- mergeConstraints(
  eq.constr,
  list(constr = c(-1, 2, 0), dir = '=', rhs = 0),
  list(constr = c(0, -1, 2), dir = '=', rhs = 0))
basis <- solution.basis(eq.constr)
stopifnot(ncol(basis$basis) == 0) # Dimension reduced to 0
stopifnot(all.equal(basis$translate, c(4/7, 2/7, 1/7)))

hitandrun documentation built on May 28, 2022, 1:09 a.m.