Re: multiply matrix

From: Lorenzo Moneta <Lorenzo.Moneta_at_cern.ch>
Date: Fri, 7 Aug 2009 11:54:08 +0200


Hi,

  Yes, A.Invert() will overwrite the matrix. Just do:

TMatrixD B = A; B.Invert();

or use the TDecompLU class:

TDecompLU lu(A);
TMatrixD B = A;
if (lu.Decompose() ) lu.Invert(B);

Lorenzo
On Aug 7, 2009, at 11:44 AM, Julia Campa Romero wrote:

> I found that the problem it is when I invert the matrix. Then A is
> overwritten, A=A¯1. Do you know how avoid it?
> Julia
> Bellow it is the program:
> ---------------------------------
> #include <TMatrixDSym.h>
> #include <TMatrixD.h>
> #include <TFile.h>
> #include <TDecompLU.h>
> #include <TDecompBase.h>
> using namespace std;
> void inverse(void){
> TMatrixD h(2,2);
> for (Int_t i=0;i<2;i++){
> for (Int_t j=0;j<2;j++){
> h[i][j]=i*3+5+j;
> //cout<<"cof"<<h[i][j]<<endl;
> // fprintf(mc,"%i %i %f\n", i, j, h[i][j]);
> }
> }
> h.Print();
> TDecompLU lu(h);
> TMatrixD p(2,2);
> if (!lu.Decompose()) {
> cout << "Decomposition failed, matrix singular ?" << endl;
> // cout << "condition number = " << h.GetCondition() << endl;
> } else {
> lu.Invert(p);
> }
> TMatrixD hi= h.Invert();
> hi.Print();
> h.Print();

>

> // TMatrixD U(2,2);
> TMatrixD U= TMatrixD(h, TMatrixD::kMult,hi);
> // U.Mult(h,hi);
> U.Print();
> }
>

> Lorenzo Moneta wrote:
>> Hi ,
>>
>> You can multiply two matrices by doing:
>>
>> TMatrixD C = A * B;
>>
>> or
>>
>> TMatrixD C(nrow,ncol);
>> C.Mult(A,B);
>>
>> If you have a problem, could you please send  a running macro  
>> reproducing it ?
>>
>> Regards
>>
>> Lorenzo
>> On Aug 7, 2009, at 11:18 AM, Julia Campa Romero wrote:
>>
>>> Hi,
>>>
>>> I have some problems when I multiply two matrix. First I made the  
>>> inversion of a 2x2 matrix A, and it is ok(A¯1). But then when I  
>>> multiply that the results it is not I, but the inversion it is not  
>>> well done.
>>> A*A¯1=I
>>> I made it through:
>>> U.Mult(a,b)
>>>
>>> Do you know what could be happening?
>>>
>>> Julia
>>>
>>> ----------------------------
>>> Confidencialidad: Este mensaje y sus ficheros adjuntos se dirige  
>>> exclusivamente a su destinatario y puede contener información  
>>> privilegiada o confidencial. Si no es vd. el destinatario  
>>> indicado, queda notificado de que la utilización, divulgación y/o  
>>> copia sin autorización está prohibida en virtud de la legislación  
>>> vigente. Si ha recibido este mensaje por error, le rogamos que nos  
>>> lo comunique inmediatamente respondiendo al mensaje y proceda a su  
>>> destrucción.
>>>
>>> Disclaimer: This message and its attached files is intended  
>>> exclusively for its recipients and may contain confidential  
>>> information. If you received this e-mail in error you are hereby  
>>> notified that any dissemination, copy or disclosure of this  
>>> communication is strictly prohibited and may be unlawful. In this  
>>> case, please notify us by a reply and delete this email and its  
>>> contents immediately. ----------------------------
>>>
>>
>
Received on Fri Aug 07 2009 - 11:54:12 CEST

This archive was generated by hypermail 2.2.0 : Sat Aug 08 2009 - 11:50:02 CEST