Package 'blockmatrix'

Title: Tools to Solve Algebraic Systems with Partitioned Matrices
Description: Some elementary matrix algebra tools are implemented to manage block matrices or partitioned matrix, i.e. "matrix of matrices" (http://en.wikipedia.org/wiki/Block_matrix). The block matrix is here defined as a new S3 object. In this package, some methods for "matrix" object are rewritten for "blockmatrix" object. New methods are implemented. This package was created to solve equation systems with block matrices for the analysis of environmental vector time series . Bugs/comments/questions/collaboration of any kind are warmly welcomed.
Authors: Emanuele Cordano
Maintainer: Emanuele Cordano <[email protected]>
License: GPL (>= 2)
Version: 1.2
Built: 2024-11-09 05:37:52 UTC
Source: https://github.com/ecor/blockmatrix

Help Index


[ S3 method for blockmatrix object

Description

[ S3 method for blockmatrix object

Usage

## S3 method for class 'blockmatrix'
 M[i = 1:nrow(M), j = 1:ncol(M),numeric_value=TRUE,blockmatrix=FALSE,...]

Arguments

M

a blockmatrix object

i, j

matrix indices (numerical or character)

numeric_value

logical value . If TRUE (Default if i,j have both length 1) and i,j have both length 1, a i,j numeric matrix is returened.

blockmatrix

logical value. If TRUE (Default if i or j have length greater than 1) a blockmatrix is returned.

...

further argument for [ method

Value

The i,j matrix as a numarical matrix if blockmatrix is FALSE, otherwise the returen oblect is a blockmatrix object. In case i is a character vector, the method returns a list of objects with name containing in i and taken from M.

Author(s)

Emanuele Cordano


'[<-' S3 Replacement method for blockmatrix object

Description

'[<-' S3 Replacement method for blockmatrix object

Usage

## S3 replacement method for class 'blockmatrix'
M[i = 1:nrow(M), j = 1:ncol(M)] <- value

Arguments

M

a blockmatrix object

i, j

matrix indices (numerical or character)

value

a blockmatrix object to be replaced

Value

The "replaced" blockmatrix object.

Note

In case i is a character vector, the elements whose names is in value is replaced.

Author(s)

Emanuele Cordano

Examples

rm(list=ls())
library(blockmatrix)
A <- array(rnorm(9,mean=1),c(3,3))
B <- 0 #array(rnorm(9,mean=2),c(3,3))
C <- 0
D <- array(rnorm(9,mean=4),c(3,3))
F <- array(rnorm(9,mean=10),c(3,3))
M <- blockmatrix(names=c("A","0","D","0"),A=A,D=D,dim=c(2,2))
E <- blockmatrix(names=c("0","F","D","0"),F=F,D=D,dim=c(2,2))
E[,1] <- M[,1]

Coerces to a Blockmatrix

Description

Coerces to a Blockmatrix

as.blockmatrix S3 method for blockmatrix, matrix and NULL object

Usage

as.blockmatrix(M = NULL, ...)

## Default S3 method:
as.blockmatrix(M, adjust_zero = TRUE, zero_element = "0",
  ...)

## S3 method for class 'blockmatrix'
as.blockmatrix(M, adjust_zero = TRUE,
  add_zero_matrix = FALSE, zero_element = "0", ...)

## S3 method for class 'matrix'
as.blockmatrix(M, nrowe = nrow(M), ncole = ncol(M),
  nrow = NULL, ncol = NULL, adjust_zero = TRUE, zero_element = "0", ...)

## Default S3 method:
as.blockmatrix(M, adjust_zero = TRUE, zero_element = "0",
  ...)

## S3 method for class 'numeric'
as.blockmatrix(M, adjust_zero = TRUE, zero_element = "0",
  ...)

Arguments

M

a matrix or blockmatrix object

...

further arguments

adjust_zero

logical value. If TRUE (Default) it replaces the zero matrices with zero_element.

zero_element

see ncol_elements or nrow_elements

add_zero_matrix

logical value. If TRUE it adds a zero-element element matrix as an object called zero_element in the blockmatrix

nrowe

number of rows for each block (element of the blockmatrix)

ncole

number of columns for each block (element of the blockmatrix)

nrow

number of rows for block-matrix

ncol

number of columns of blockmatrix

Details

In case of coercion from a matrix, ncole and/or ncol must be a submultiple of the number of columns of M; nrowe and/or nrow must be a submultiple of the number of rows of M.

Author(s)

Emanuele Cordano


as.matrix S3 method for blockmatrix object

Description

as.matrix S3 method for blockmatrix object

Usage

## S3 method for class 'blockmatrix'
as.matrix(x, zero_element = "0", ...)

Arguments

x

a blockmatrix object

zero_element

(see ncol_elements or nrow_elements)

...

further arguments (see ncol_elements or nrow_elements)

Author(s)

Emanuele Cordano


blockmatmult implements the implents betwwen two blockmatrix ( see matmult for matrx objects)

Description

blockmatmult implements the implents betwwen two blockmatrix ( see matmult for matrx objects)

Usage

blockmatmult(x, y, ...)

Arguments

x, y

blockmatrix objects

...

further arguments

Value

The inner product between x and y as a blockmatrix object

Author(s)

Emanuele Cordano


This function builds a blockmatrix

Description

This function builds a blockmatrix

Usage

blockmatrix(dim, value = NULL, names = NULL, list = NULL,
  use.as.blockmatrix = TRUE, adjust_zero = TRUE, add_zero_matrix = FALSE,
  zero_element = "0", ...)

Arguments

dim

dimension of a block-matrix

value

matrix containing the indices (names) of blockmatrix element. If missing, it is NULL (Default). (sse value

names

charcarcter vector containing the names for each matrix-type element of the block-matrix

list

list containing the matrices to be inserted into the block-matrix. If NULL (Default) the matrix are faken from ...

use.as.blockmatrix

logical value. If TRUE (Default) the method as.blockmatrix for blockmatrix object is applied to the output blockmatrix before being returned.

adjust_zero, add_zero_matrix, zero_element

arguments passed to as.blockmatrix

...

elements of the block-matrix.

Author(s)

Emanuele Cordano

See Also

as.blockmatrix

Examples

rm(list=ls())
library(blockmatrix)

A <- array(rnorm(9,mean=1),c(3,3))
B <- 0 #array(rnorm(9,mean=2),c(3,3))
C <- 0
D <- array(rnorm(9,mean=4),c(3,3))
F <- array(rnorm(9,mean=10),c(3,3))

M <- blockmatrix(names=c("A","0","D","0"),A=A,D=D,dim=c(2,2))
E <- blockmatrix(names=c("0","F","D","0"),F=F,D=D,dim=c(2,2))

R <- M+E
S <- solve(R)
P <- blockmatmult(R,E)

l <- list(A=A,B=B,C=C,D=D,F=F)
mv <- array(c("A","B","C","D","F","F"),c(3,2))
BB <- blockmatrix(value=mv,list=l)

dim S3 method for blockmatrix object

Description

dim S3 method for blockmatrix object

Usage

## S3 method for class 'blockmatrix'
dim(x)

Arguments

x

a blockmatrix object

Author(s)

Emanuele Cordano


is.zero.bolockmatrix

Description

is.zero.bolockmatrix

Usage

is.zero.blockmatrix(M, not.a.blockmatrix = FALSE)

Arguments

M

a blockmatrix object

not.a.blockmatrix

value to be returned in case M is not a a blockmatrix object

Value

logical value in case M is a zero blockmatrix

Author(s)

Emanuele Cordano


length S3 method for blockmatrix object

Description

length S3 method for blockmatrix object

Usage

## S3 method for class 'blockmatrix'
length(x)

Arguments

x

a blockmatrix object

Author(s)

Emanuele Cordano


Math and Ops group of S3 methods for blockmatrix object

Description

Math and Ops group of S3 methods for blockmatrix object

Usage

## S3 method for class 'blockmatrix'
Math(x, as.blockmatrix = TRUE, ...)

## S3 method for class 'blockmatrix'
Ops(e1, e2)

Arguments

x, e1, e2

blockmatrix objects

as.blockmatrix

logical value. If TRUE (Default), the output is a blockmatrix object

...

further arguments

Author(s)

Emanuele Cordano


names S3 method for blockmatrix object

Description

names S3 method for blockmatrix object

Usage

## S3 method for class 'blockmatrix'
names(x)

Arguments

x

a blockmatrix object

Author(s)

Emanuele Cordano


names<- S3 Replacement method for blockmatrix object

Description

names<- S3 Replacement method for blockmatrix object

Usage

## S3 replacement method for class 'blockmatrix'
 names(x) <- value

Arguments

x

a blockmatrix object

value

character vector with the new names replacing the old names

Value

x with new names and replaced names in the value matrix.

Author(s)

Emanuele Cordano

Examples

library(blockmatrix)

M <- as.blockmatrix(array(rnorm(100),c(10,10)),nrow=2,ncol=2)


pn <- paste("p",names(M),sep="")
names(M) <- pn

ncol_elements S3 method for blockmatrix object

Description

ncol_elements S3 method for blockmatrix object

ncol_elements S3 method for blockmatrix object

Usage

ncol_elements(M, zero_element = "0", ...)

## Default S3 method:
ncol_elements(M, zero_element = "0", ...)

## S3 method for class 'blockmatrix'
ncol_elements(M, zero_element = "0", ...)

Arguments

M

a blockmatrix object

zero_element

character value indicating a zero matrix. Default is "0"

...

further arguments

Value

The number of columns of a matrix-type element of M. It is NA if the elements has different number of columns.

Author(s)

Emanuele Cordano


ncol S3 method for blockmatrix object

Description

ncol S3 method for blockmatrix object

Usage

## S3 method for class 'blockmatrix'
ncol(M)

Arguments

M

a blockmatrix object

Value

Numbner of columns of blockmatrix M

Author(s)

Emanuele Cordano


nrow_elements S3 method for blockmatrix object

Description

nrow_elements S3 method for blockmatrix object

nrow_elements S3 method for blockmatrix object

Usage

nrow_elements(M, zero_element = "0", ...)

## Default S3 method:
nrow_elements(M, zero_element = "0", ...)

## S3 method for class 'blockmatrix'
nrow_elements(M, zero_element = "0", ...)

Arguments

M

a blockmatrix object

zero_element

character value indicating a zero matrix. Default is "0"

...

further arguments

Value

The number of rows of a matrix-type element of M. It is NA if the elements has different number of rows.

Author(s)

Emanuele Cordano


nrow S3 method for blockmatrix object

Description

nrow S3 method for blockmatrix object

Usage

## S3 method for class 'blockmatrix'
nrow(M)

Arguments

M

a blockmatrix object

Value

Number of rows of blockmatrix M

Author(s)

Emanuele Cordano


solve

Description

dim S3 solve for blockmatrix object

Usage

## S3 method for class 'blockmatrix'
solve(a, b = NULL, as.blockmatrix = TRUE, ...)

Arguments

a

a blockmatrix or numeric object

b

a blockmatrix or numeric object. If omitted, it is NULL. See Details.

as.blockmatrix

logical value. If TRUE (Default), the output is a blockmatrix object

...

further arguments for method solve

Value

the object x such that a * x = b where * is the matrix product.

Note

If b is missing, i.e. NULL, it will be replaced by the corresponding identity matrix. So x is calculated as the right inverse of a. The matrix system must be nonsingular and nonhomogeneous.

Author(s)

Emanuele Cordano


t 'transpose' S3 method for blockmatrix object

Description

t 'transpose' S3 method for blockmatrix object

Usage

## S3 method for class 'blockmatrix'
t(x)

Arguments

x

a blockmatrix object

Author(s)

Emanuele Cordano


value S3 method for blockmatrix object

Description

value S3 method for blockmatrix object

value S3 method for blockmatrix object

Usage

value(M)

## Default S3 method:
value(M)

## S3 method for class 'blockmatrix'
value(M)

Arguments

M

a blockmatrix object

Value

The character matrix without numerical values (e.g. only the matrix M$value)

Author(s)

Emanuele Cordano


value<- S3 Replacement method for blockmatrix object

Description

value<- S3 Replacement method for blockmatrix object

value<- S3 Replacement method for blockmatrix object

Usage

value(M) <- value

## Default S3 replacement method:
 value(M) <- value

## S3 replacement method for class 'blockmatrix'
 value(M) <- value

Arguments

M

a blockmatrix object

value

object replaced matrix

Value

Replaces M$value with a new matrix value

Author(s)

Emanuele Cordano