solve                  package:base                  R Documentation

_S_o_l_v_e _a _S_y_s_t_e_m _o_f _E_q_u_a_t_i_o_n_s

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

     This generic function solves the equation 'a %*% x = b' for 'x',
     where 'b' can be either a vector or a matrix.

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

     solve(a, b, ...)

     ## Default S3 method:
     solve(a, b, tol = 1e-7, LINPACK = FALSE, ...)

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

       a: a square numeric or complex matrix containing the
          coefficients of the linear system.

       b: a numeric or complex vector or matrix giving the right-hand
          side(s) of the linear system.  If missing, 'b' is taken to be
          an identity matrix and 'solve' will return the inverse of
          'a'.

     tol: the tolerance for detecting linear dependencies in the
          columns of 'a', if LINPACK is used.

 LINPACK: logical. Should LINPACK be used (for compatibility with R <
          1.7.0)?

     ...: further arguments passed to or from other methods

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

     As from R 1.3.0, 'a' or 'b' can be complex, in which case LAPACK
     routine 'ZESV' is used. This uses double complex arithmetic which
     might not be available on all platforms.

     The row and column names of the result are taken from the column
     names of 'a' and of 'b' respectively.  As from R 1.7.0 if 'b' is
     missing the column names of the result are the row names of 'a'. 
     No check is made that the column names of 'a' and the row names of
     'b' are equal.

     For back-compatibility 'a' can be a (real) QR decomposition,
     although 'qr.solve' should be called in that case. 'qr.solve' can
     handle non-square systems.

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

     Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S
     Language_. Wadsworth & Brooks/Cole.

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

     'solve.qr' for the 'qr' method, 'backsolve', 'qr.solve'.

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

     hilbert <- function(n) { i <- 1:n; 1 / outer(i - 1, i, "+") }
     h8 <- hilbert(8); h8
     sh8 <- solve(h8)
     round(sh8 %*% h8, 3)

     A <- hilbert(4)
     A[] <- as.complex(A)
     ## might not be supported on all platforms
     try(solve(A))

