Vector and Matrix opreations

I’m doing a rather long tedious matrix manipulation. I have a few things that I would like to understand.

  1. TMatrix does not appear to have a friend with TVector, so I’m assuming that vectors must be declared as TMatrix with dimension 1 by N or N by 1. Is this correct?

  2. When I do the multiplication it appears that a number of temporary TMatrix classes get allocated. Is there any general rules that people suggest to minimize the creation of intermediary TMatrix?

  3. I have declared
    TMatrix *H = new TMatrix(6,6)
    and
    TTMatrix *Xminus = new TMatrix(1,6)

Mutiplying these on the command line appears to work fine. However, when I embed them in a script I get the error:

Error: Can’t call TMatrixD::AmultB((*H),(*Xminus),1) in current scope

Why does one case work and not the other?

Example code added as an attachment.

Regards to all.
Chris
test2.C (459 Bytes)

Hi Chris,

TMatrixD::AmultB is a protected function. Use instead the standard TMatrixD constructors, eg in your example replace
TMatrixD X;
X.AmultB ((*H),(*Xminus),1);
by
TMatrixD X(*H, TMatrixDBase::kMult, *Xminus);

Rene

That helps a lot. Thank you!

Hi Chris,

Concerning 1) . They do exist. look in TVectorD.h, or TVectorF.h

TVectorD &operator*=(const TMatrixD &a);
TVectorD &operator*=(const TMatrixDSym &a);
TVectorD &operator*=(const TMatrixDSparse &a);

or

TVectorD operator* (const TMatrixD &a, const TVectorD &source);
TVectorD operator* (const TMatrixDSym &a, const TVectorD &source);
TVectorD operator* (const TMatrixDSparse &a, const TVectorD &source);

issue 2) , I do not understand

Eddy

hi,
Is it possible to multiply a n x 1 TVectorD by an m x n matrix, when m > n and the vector doesn’t own its own memory? The size of the vector obviously has to increase from m to n, and this doesn’t seem to be possible.

I got around this by coding up matrix multiplication of C++ std vectors which was very easy and intuitive, but it’s not exactly an elegant solution.
Many thanks
Hamish

Hi,

If[quote}the vector doesn’t own its own memory? The size of the vector obviously has to increase from m to n,[/quote]then you would need to first copy the vector’s value into the a difference vector of the correct larger size …

Philippe.