# how to multiply a constant to a matrix?

4 messages
Open this post in threaded view
|
Report Content as Inappropriate

## how to multiply a constant to a matrix?

 This is very strange: I want compute the following in R: g = B/D * solve(A) where B and D are  quadratics so they are just a scalar number, e.g. B=t(a) %*% F %*% a; I want to multiply B/D to A^(-1), but R just does not allow me to do that and it keeps complaining that "nonconformable array, etc." I tried the following two tricks and they worked: as.numeric(B/D) * solve(A) diag(as.numeric(B/D), 5, 5) %*% solve (A) ---------------------------- But if R cannot intelligently do scalar and matrix multiplication, it is really problemetic. It basically cannot be used to do computations, since in complicated matrix algebras, you have to distinguish where is scalar, and scalars obtained from quadratics cannot be directly used to multiply another matrix, etc. It is going to a huge mess... Any thoughts?         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Open this post in threaded view
|
Report Content as Inappropriate

## Re: how to multiply a constant to a matrix?

 imagine when you have complicated matrix algebra computation using R, you cannot prevent some middle-terms become quadratic and absorbs into one scalar, right? if R cannot intelligently determine this, and you  have to manually add "drop" everywhere, do you think it is reasonable? On 5/23/06, Patrick Burns <[hidden email]> wrote: > > I think > > drop(B/D) * solve(A) > > would be a more transparent approach. > > It isn't that R can not do what you want, it is that > it is saving you from shooting yourself in the foot > in your attempt.  What you are doing is not really > a matrix computation. > > > Patrick Burns > [hidden email] > +44 (0)20 8525 0696 > http://www.burns-stat.com> (home of S Poetry and "A Guide for the Unwilling S User") > > Michael wrote: > > >This is very strange: > > > >I want compute the following in R: > > > >g = B/D * solve(A) > > > >where B and D are  quadratics so they are just a scalar number, e.g. > B=t(a) > >%*% F %*% a; > > > >I want to multiply B/D to A^(-1), > > > >but R just does not allow me to do that and it keeps complaining that > >"nonconformable array, etc." > > > > > >I tried the following two tricks and they worked: > > > >as.numeric(B/D) * solve(A) > > > >diag(as.numeric(B/D), 5, 5) %*% solve (A) > > > >---------------------------- > > > >But if R cannot intelligently do scalar and matrix multiplication, it is > >really problemetic. > > > >It basically cannot be used to do computations, since in complicated > matrix > >algebras, you have to distinguish where is scalar, and scalars obtained > from > >quadratics cannot be directly used to multiply another matrix, etc. It is > >going to a huge mess... > > > >Any thoughts? > > > >       [[alternative HTML version deleted]] > > > >______________________________________________ > >[hidden email] mailing list > >https://stat.ethz.ch/mailman/listinfo/r-help> >PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html> > > > > > > > >         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Open this post in threaded view
|
Report Content as Inappropriate