# 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