TDecompSVD not working

Hi all,

I am trying to use TDecompSVD to solve Ax=b, where I have A saved as a TH2 with 300x300 bins. And I have b saved as a TH1 with 300 bins.

{

  TH2D myhist("h1","2DGaussian",300,-3,3,300,-3,3);
 TRandom3 foo(12345);
 for(int i=0;i<10000;i++)
     {
      myhist->Fill(foo.Gaus(0,1),foo.Gaus(0,1));
     }

  const int exbins=myhist->GetNbinsX();
  const int whybins=myhist->GetNbinsY();

  TMatrixD Amatrix(exbins,whybins);
  Amatrix.Zero();
  for (int xbin=1;xbin<=exbins;xbin++)
    {
      for (int ybin=1;ybin<=whybins;ybin++)
	{
          Amatrix(whybins-ybin,xbin-1)=myhist->GetBinContent(xbin,ybin);
        }//end of loop over y bins                                                                                            
    }//end of loop over xbins                                                                                                 

  TDecompSVD svd(Amatrix,0.00001); //Decomp my A matrix with a tolerance of 1e-5
  
  Bool_t ok;
  
  TH1D *hdata = new TH1D("mydataexample","mydataexample",300,0.01,10);
  for (int i=0;i<10000;i++)
     {
        hdata->Fill(foo.Gaus(2,5));
     }

    const int exdata=hdata->GetNbinsX();  
    
    TMatrixD matdata(exdata,1);
    matdata.Zero();
    
  for (int xbin=1;xbin<=exdata;xbin++)
    {
      matdata(xbin-1,0)=hdata->GetBinContent(xbin);
    }//end of loop over xbins  


   const TVectorD c_svd = svd.Solve(matdata,ok);
   
   }

This throws an error, does anyone have any ideas?

Hi,

Your code is not correrct. Attached is after the correction and it is working for me

Best

Lorenzo

Untitled.C (1.3 KB)