[Gretl-users] matrix operation efficiency question

oleg_komashko at ukr.net oleg_komashko at ukr.net
Sat Nov 5 12:01:57 EDT 2016

Dear Allin, 
Than you! 
You allwas manage to understand my 
English  at 100%! 
This time comparison is just 
I needed but forgot to ask 


5 листопада 2016, 17:56:59, від "Allin Cottrell" < cottrell at wfu.edu >: 

On Sat, 5 Nov 2016, oleg_komashko at ukr.net  wrote:

> Dear all,
> Let X be a matrix and A a symmetric matrix
> (dimentions are compatible)
> What is the best way to compute
> x'A^-1x

Well, it looks like a case of inversion + qform() versus
"right division". So let the horses race:

/* x' A^{-1} x : best method? */

set seed 775632

scalar m = 50
scalar n = 10
scalar p = 3

matrix x = mnormal(n, p)
matrix Z = mnormal(m, n)
matrix A = Z'Z

# check equivalence
eval qform(x', inv(A))
eval x'(A\x)

set stopwatch

loop 5000 -q
   matrix R = qform(x', inv(A))
printf "method 1: %gs\n", $stopwatch

loop 5000 -q
   matrix R = x'(A\x)
printf "method 2: %gs\n", $stopwatch

method 1: 0.0922s
method 2: 0.0410s

And the spotted pony wins.

Gretl-users mailing list
 Gretl-users at lists.wfu.edu 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wfu.edu/pipermail/gretl-users/attachments/20161105/ed2e34de/attachment.html>

More information about the Gretl-users mailing list