[R] multiplying matrix by vector of times
Gad Abraham
g.abraham at ms.unimelb.edu.au
Tue Mar 13 23:37:15 CET 2007
> Thanks for the tip about the empty vector, I ever knew you could do that. I
> just have one problem,
>
> Lets say Q is a 2x2 matrix
> p is a 1x2 matrix
> q is a 2x1 matrix
> y is vector of times, say y = c(5, 10)
>
> How do I multiply Q by each time y[i]?
>
> I would like to get the answer to the equation
>
> loglik[i] <- log(p %*% expm(Q * y[i]) %*% q)
>
> Where first y=5 and then y=10 so that the answers to loglik for each i are
> put into the empty vector.
>
> I'm sure that I am missing something fairly obvious here but can't put my
> finger on it.
That's just what the code in my last message is doing:
iterating over the y vector, multiplying Q by each y[i], and storing the
result in a different cell of loglik.
So you're not multiplying Q by a vector y, but Q by a scalar y[i].
Have a look at the R Introduction at
http://cran.r-project.org/doc/manuals/R-intro.html,
especially section 2.
--
Gad Abraham
Department of Mathematics and Statistics
The University of Melbourne
Parkville 3010, Victoria, Australia
email: g.abraham at ms.unimelb.edu.au
web: http://www.ms.unimelb.edu.au/~gabraham
More information about the R-help
mailing list