Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: Exponential function on matrix


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Exponential function on matrix
Date   Tue, 19 Jun 2012 21:33:03 +0100

You can do this in Mata.

. mata :
: exp((0,1\2,3))
                 1             2
    +-----------------------------+
  1 |            1   2.718281828  |
  2 |  7.389056099   20.08553692  |
    +-----------------------------+

You can also pass a Stata matrix into Mata to do this and pull back the result.

. matrix foo = (0,1\2,3)

. mata : st_matrix("foobar", exp(st_matrix("foo")))

. mat li foobar

foobar[2,2]
           c1         c2
r1          1  2.7182818
r2  7.3890561  20.085537

On Tue, Jun 19, 2012 at 9:00 PM, Haiyong Xu <hxu@mednet.ucla.edu> wrote:

> I want to apply exponential function on each cell of a matrix. Is there an
> easy way such as exp(matA) instead of loop? Thank you very much!
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index