# Re: [R] how to multiply a constant to a matrix?

From: Michael <comtech.usa_at_gmail.com>
Date: Wed 24 May 2006 - 16:14:21 EST

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 <pburns@pburns.seanet.com> 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
> patrick@burns-stat.com
> +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]]
> >
> >______________________________________________
> >R-help@stat.math.ethz.ch 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]]

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed May 24 16:19:49 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 30 May 2006 - 02:10:24 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.