Re: Invert Matrix

From: Lorenzo Moneta <Lorenzo.Moneta_at_cern.ch>
Date: Wed, 5 Aug 2009 15:22:33 +0200


Hi,

On Aug 5, 2009, at 1:01 PM, Julia Campa Romero wrote:

> Hi,
>
> I want to invert a 39x39 symmetric matrix. But I have some
> difficulties.
> First, I fill the upper diagonal elements and then I complete it.
> The programa to fill the Matrix is:
> ------------------------------------------------------------------
> TMatrixD h(39,39);
> //CON are the values of the elements
> for (Int_t i=0;i<39;i++){
> for (Int_t j=i;j<39;j++){
> h[i][j]=CON[i][j];
> }
> //completed the low diagonal elements
> for (Int_t j=0;j<i;j++){
> h[i][j]=CON[j][i];
> }
> }
> ----------------------------------------------
> --Then to check whether the matrix is singular before attempting to
> invert it I write:
> -------------------------
> TDecompLU lu(h);
> TMatrixD p;
> if (!lu.Decompose()) {
> cout << "Decomposition failed, matrix singular ?" << endl;
> } else {
> lu.Invert(p);
> }

you need to declare correctly the size of p; Do:

TMatrixD p(39,39);

> ----
> And it gives me the following error:
>
> >>Error in <TDecompLU::Invert(TMatrixD &>: Input matrix has wrong
> shape
>
> --Then when I made
>
> >TMatrixD hi=h.Invert();
> It is gives me:
> >>Error in <TDecompLU::InvertLU>: matrix is singular, 1 diag
> elements < tolerance of 2.2204e-16
>
>

Some diagonal elements are too small. You can try either increasing the tolerance using lu.SetTol( tol) , if you are confident that the matrix is not singular or try to use another method like the SVD decomposition.

  Best Regards

  Lorenzo

> Could you explain me what it is happening?
>
> Julia Campa
>
>
>
>
> ----------------------------
> 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 Wed Aug 05 2009 - 15:22:37 CEST

This archive was generated by hypermail 2.2.0 : Wed Aug 05 2009 - 17:50:02 CEST