Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

# Re: st: Why is Mata much slower than MATLAB at matrix inversion?

 From Richard Herron <[email protected]> To [email protected] Subject Re: st: Why is Mata much slower than MATLAB at matrix inversion? Date Fri, 20 Jul 2012 12:17:26 -0400

```Patrick, -cholinv()- requires a symmetric positive definite matrix,
but I don't think you M matrix is PD. Try -luinv()-.

Although for most use cases your matrix will be symmetric, right? Then
you should use -invsym()- or a solve function.

Richard Herron

On Thu, Jul 19, 2012 at 9:22 PM, Patrick Roland <[email protected]>
wrote:
>
> I'm comparing two code snippets. In Mata:
>
> mata
> timer_on(1)
> M = rnormal(2000,2000,0,1)
> J = cholinv(M)
> timer_off(1)
> timer()
> end
>
> In MATLAB:
>
> tic;
> M = normrnd(0,1,2000,2000);
> J = inv(M);
> toc;
>
> I find that MATLAB is about 20 times faster (1.5 seconds vs 30
> seconds). Is there something I'm missing here, or is MATLAB just much
> faster at matrix inversion? I'd much prefer to use Mata because of
> integration with Stata, but if the speed difference is going to be on
> this order then MATLAB is more attractive.
>
>
> Any input here is appreciated.
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index