[R] exponentiate elements of a whole matrix

Berwin A Turlach berwin at maths.uwa.edu.au
Wed Oct 13 13:02:13 CEST 2010


On Wed, 13 Oct 2010 11:51:39 +0100
"Maas James Dr (MED)" <J.Maas at uea.ac.uk> wrote:

> I've tried hard to find a way to exponentiate each element of a whole
> matrix such that if I start with A
> 
> A = [ 2   3
>       2   4]
> 
> I can get back B
> 
> B = [ 7.38   20.08
>       7.38   54.60]
> 
> I've tried
> 
> B <- exp(A) but no luck.

What have you tried exactly?  And with which version?  This should work
with all R versions that I am familiar with, e.g.:

R> A <- matrix(c(2,2,3,4),2,2)
R> A
     [,1] [,2]
[1,]    2    3
[2,]    2    4
R> B <- exp(A)
R> B
         [,1]     [,2]
[1,] 7.389056 20.08554
[2,] 7.389056 54.59815

Cheers,

	Berwin

========================== Full address ============================
Berwin A Turlach                      Tel.: +61 (8) 6488 3338 (secr)
School of Maths and Stats (M019)            +61 (8) 6488 3383 (self)
The University of Western Australia   FAX : +61 (8) 6488 1028
35 Stirling Highway                   
Crawley WA 6009                e-mail: berwin at maths.uwa.edu.au
Australia                        http://www.maths.uwa.edu.au/~berwin



More information about the R-help mailing list