Learn R Programming

BigDataStatMeth (version 1.0.3)

bdSolve: Solve Linear System AX = B (In-Memory)

Description

Solves the linear system AX = B where A is an N-by-N matrix and X and B are N-by-NRHS matrices. The function automatically detects if A is symmetric and uses the appropriate solver.

Usage

bdSolve(A, B)

Value

Numeric matrix X, the solution to AX = B.

Arguments

A

Numeric matrix. The coefficient matrix (must be square).

B

Numeric matrix. The right-hand side matrix (must have same number of rows as A).

Details

This function provides an efficient implementation for solving linear systems using LAPACK routines. Key features:

  • Automatic detection of matrix properties:

    • Checks for matrix symmetry

    • Selects optimal solver based on matrix structure

  • Solver selection:

    • Symmetric systems: Uses LAPACK's dsysv routine

    • Non-symmetric systems: Uses LAPACK's dgesv routine

  • Performance optimizations:

    • Automatic workspace sizing

    • Efficient memory management

    • Support for multiple right-hand sides

The implementation ensures:

  • Robust error handling

  • Efficient memory usage

  • Numerical stability

  • Support for various matrix sizes

References

  • Anderson, E. et al. (1999). LAPACK Users' Guide, 3rd Edition. SIAM, Philadelphia.

  • Golub, G. H., & Van Loan, C. F. (2013). Matrix Computations, 4th Edition. Johns Hopkins University Press.

See Also

  • bdSolve_hdf5 for solving systems with HDF5-stored matrices

  • solve for R's built-in solver

Examples

Run this code
library(BigDataStatMeth)

# Create test matrices
n <- 500
m <- 500

A <- matrix(runif(n*m), nrow = n, ncol = m)
B <- matrix(runif(n), nrow = n)
AS <- A %*% t(A)  # Create symmetric matrix

# Solve using bdSolve
X <- bdSolve(A, B)

# Compare with R's solve
XR <- solve(A, B)
all.equal(X, XR, check.attributes=FALSE)

Run the code above in your browser using DataLab