Learn R Programming

bigutilsr (version 0.3.11)

solve_linear_system: Solve (A + lam I) x = b

Description

Solve (A + lam I) x = b

Usage

solve_linear_system(A, b, add_to_diag = 0)

Value

The best solution x of this linear system.

Arguments

A

A symmetric square matrix.

b

A vector.

add_to_diag

One value to add to the diagonal of A (lam). Default is 0.

Examples

Run this code
A <- matrix(rnorm(4), 2); A[1, 2] <- A[2, 1]  # should be symmetric
x <- rnorm(2)
b <- A %*% x
x2 <- drop(solve(A, b))
x3 <- solve_linear_system(A, b)
rbind(x, x2, x3)

Run the code above in your browser using DataLab