solve_ols: Iteratively solve linear system of equations.

Description Usage Arguments Value Examples

Description

solve linear system of equations using Gauss-Seidal or Jacobi.

Usage

1
2
3
solve_ols(A, b, x0 = rep(0, length(b)), method = c("Gauss-Seidel",
  "Jacobi"), maxit = 15000, eps = 1e-05, parallelize = FALSE,
  cores = 1)

Arguments

A

a numeric matrix containing the coefficients of the linear system.

b

a numeric vector giving the right-hand side of the linear system.

x0

the intial solution vector.

method

a character string indicating which iterative method is to use. Either 'Gauss-Seidel' or 'Jacobi'.

maxit

Maximum number of passes over the data for all lambda values; default is 15000.

eps

Convergence threshold. Defaults value is 1E-7.

parallelize

Logical. only useful when method == 'Jacobi'. Should Jacobi method be implemented in parallel(TRUE) or not(default=FALSE).

cores

The number of cores to use for parallel execution. Default is 1.

Value

x.last solution vector found in the last iteration.

x.all a list of solutions of all iterations.

time a vector recording time spent at iterations.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
A = matrix(0, nrow = 100, ncol = 100)
diag(A) = rep(2, 100)
for (i in 1:100){
 for (j in 1:100){
  if(abs(i-j)==1) A[i,j] = -1
  }
}
v = rep(c(1,0), 50)
est = solve_ols(A = A, b = A%*%v, method = 'Gauss-Seidel')
print(max(abs(est$x.last - v)))

yuxuanzhao2295/CompStat_hw2 documentation built on May 22, 2019, 12:19 p.m.