Learn R Programming

comphy (version 1.0.5)

illcond_sample: Ill-conditioned sampling

Description

Random sampling, based on the uniform distribution, of the right-hand side, \(b\), of a linear system and of a perturbation, \(\Delta b\), so that the solution of \(Ax=b\) is very different from the solution of \(Ax=b+\Delta b\).

Usage

illcond_sample(A, bmax = 100, Dbmax = 1, ncyc = 1e+05, iseed = NULL)

Value

A named list with names b, a vector equal of the right-hand side of the linear system, and Db, a vector equal to the perturbations, \(\Delta b\), to be applied to \(b\).

Arguments

A

The \(n \times n\) matrix of coefficients of the unknowns in the linear system.

bmax

A numeric number providing the interval, (0,bmax), in which the \(n\) uniformly random components of \(b\) are selected. Default value is 100.

Dbmax

A numeric number providing the interval, (0,Dbmax), in which the \(n\) uniformly random components of \(\Delta b\) are selected. Default value is 1.

ncyc

An integer indicating the number of uniform random selection of the \(n\) components of \(b\) and the \(n\) components of \(\Delta b\). The higher this number, the higher the chance of getting a high relative solution number, but the longer the execution time of the function. Default is 100000.

iseed

An integer. The seed starting random generation. If a value is provided, the (pseudo-)random generation will reproduce exactly the same \(b\) and \(\Delta b\). Default is NULL, which means that the seed will be randomly chosen at every execution of the function.

Details

The degree of ill-conditioning of a system is not only measured by the matrix's condition number, but also from the solution relative error. If \(\Delta x\) is the difference between the solution, \(x\), of the system related to \(b\) and the solution, \(x'\), of the system related to \(b'= b-\Delta b\), then the ratio of the norm of \(\Delta x\) and the norm of \(x\), is the solution relative error. Norms are Frobenius norms. This function returns a named list with b and Db the chosen \(b\) and \(\Delta b\), based on random sampling of a specified region.

Examples

Run this code
# This is a simple but ill-conditioned matrix
A <- matrix(c(2,1,1.99,1),ncol=2)

# Select b and Db randomly, starting with iseed=2341
ltmp <- illcond_sample(A,iseed=2341)
names(ltmp)

# b and b'
b <- ltmp$b
Db <- ltmp$Db
b2 <- b-Db

# Solution for b
x <- solve(A,b)
print(x)

# Solution for b'
x2 <- solve(A,b2)
print(x2)

# Difference
Dx <- x-x2

# Solution relative error (Frobenius norm)
print(norm(Dx,"F")/norm(x,"F"))

# Upper limit
Ainv <- solve(A)
print(norm(A,"F")*norm(Ainv,"F")*norm(Db,"F")/norm(b,"F"))

Run the code above in your browser using DataLab