solve_ols: Iterative solver for Linear Systems of Equations

Description Usage Arguments Value Examples

View source: R/solve_ols.R

Description

solve_ols can use Gauss-Seidel , Jacobi(sequential), or Jacobi (parallel) to solve a system of equations Ax = b given A and b.

Usage

1
solve_ols(A, b, method = "gs", iter = 5000, ncores = NULL)

Arguments

A

Matrix with n rows and p columns

b

Vector of length n

method

Iterative method for solving Ax = b, either 'gs' for Gauss-Seidel (sequential), 'jacobi' for Jacobi (sequential), or 'parallel' for parallel Jacobi.

iter

Number of iterations for the solver.

ncores

Optionally set number of cores. If left empty, solve_ols will get the number of cores on the user's system and subtract 1.

Value

Numeric vector x, solution to Ax = b.

Examples

1
2
3
4
5
A = diag(2, nrow = 20)
A[abs(row(A) -col(A)) == 1] = -1
b = A%*%(0.5*1:20)
solve_ols(A,b)
solve_ols(A,b, method = 'parallel', iter = 1000, ncores = 2)

stevebroll/stsci6520hw2 documentation built on Dec. 23, 2021, 5:32 a.m.