[R] quadratic form

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Nov 3 15:17:15 CET 2005


Alvarez Pedro <palvarez7777 at yahoo.es> writes:

> On page 22 of the R-introduction guide it's written:
> 
> the quadratic form x^{'} A^{-1} x which is used in
> multivariate computations, should be computed by
> something like x%*%solve(A,x), rather than computing
> the inverse of A.
> 
> Why isn't it good to compute t(x) %*% solve(A) %*% x?

It's just a waste of CPU time. For k x k matrices, solution of Ax=b is
of computational complexity O(k^2) whereas inversion of A is O(k^3).
This is obviously more important for k=1000 than for k=5.

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




More information about the R-help mailing list