spam solve               package:spam               R Documentation

_L_i_n_e_a_r _E_q_u_a_t_i_o_n _S_o_l_v_i_n_g _f_o_r _S_p_a_r_s_e _M_a_t_r_i_c_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     'backsolve' and 'forwardsolve' solve a system of linear equations
     where the coefficient matrix is upper or lower triangular. 
      'solve' solves a linear system or computes the inverse of a
     matrix if the right-hand-side is missing.

_U_s_a_g_e:

     solve(a, b, ...)

     backsolve(r, x, ...)
     forwardsolve(l, x, ...)

_A_r_g_u_m_e_n_t_s:

       a: symmetric positive definite matrix of class 'spam'.

     l,r: object of class 'spam' or 'spam.chol.'_method_ returned by
          the function 'chol'.

     x,b: vector or regular matrix of right-hand-side(s) of a system of
          linear equations.

     ...: further arguments passed to or from other methods, see
          Details below.

_D_e_t_a_i_l_s:

     We can solve 'A %*% x = b' by first computing the Cholesky
     decomposition 'A = t(R)%*%R)', then solving 't(R)%*%y = b' for
     'y', and finally solving 'R%*%x = y' for 'x'. 'solve' combines
     'chol', a Cholesky decomposition of a symmetric positive definite
     sparse matrix, with 'forwardsolve' and then 'backsolve'.

     'forwardsolve' and 'backsolve' solve a system of linear equations
     where the coefficient matrix is lower ('forwardsolve') or upper
     ('backsolve') triangular.  Usually, the triangular matrix is
     result from a 'chol' call and it is not required to transpose it
     for 'forwardsolve'.  Note that arguments of the default methods
     'k', 'upper.tri' and 'transpose' do not have any effects here.

     If the right-hand-side in 'solve' is missing it will compute the
     inverse of a matrix. For details about the specific Cholsesky
     decomposition, see 'chol'.

     Recall that the Cholesky factors are from ordered matrices.

_N_o_t_e:

     There is intentionally no S3 distinction between the classes
     'spam' and 'spam.chol.'_method_.

_A_u_t_h_o_r(_s):

     Reinhard Furrer, based on Ng and Peyton (1993) Fortran routines

_R_e_f_e_r_e_n_c_e_s:

     See references in 'chol'.

_S_e_e _A_l_s_o:

     'det', 'chol' and 'ordering'.

_E_x_a_m_p_l_e_s:

     # Generate multivariate form a covariance inverse:
     # (usefull for GRMF)
     set.seed(13)
     n <- 25    # dimension
     N <- 1000  # sample size
     Sigmainv <- .25^abs(outer(1:n,1:n,"-"))
     Sigmainv <- as.spam( Sigmainv, eps=1e-4)

     Sigma <- solve( Sigmainv)  # for verification 
     iidsample <- array(rnorm(N*n),c(n,N))

     mvsample <- backsolve( chol(Sigmainv), iidsample)
     norm( var(t(mvsample)) - Sigma, type="HS")

     # compare with:
     mvsample <- backsolve( chol(as.matrix( Sigmainv)), iidsample)
     norm( var(t(mvsample)) - Sigma, type="HS")


     # 'solve' step by step:
     b <- rnorm( n)
     R <- chol(Sigmainv)
     norm( backsolve( R, forwardsolve( R, b))-
           solve( Sigmainv, b),type="HS") 
     norm( backsolve( R, forwardsolve( R, diag(n)))- Sigma,type="HS") 

