# Faster interpolation in TGraph2D?

Dear Rooters,

I am making a TGraph2D with 400200 bins from which I need to interpolate 4002000 points. My approach to do this is a simple nested loop where I do g->Interpolate(x,y). I have calculated that this would take more than a week to run through (1sec per point) which of course is way too much. So I am asking for any tips how to do this more clever and faster!

Regards,
Karin

Hi Karin,

I suggest to use a TH2F instead of a TGraph2D. See small example below.
Getting 100000 points interpolated from the TH2 takes less than 1 second.

Rene

```void int2() { Int_t nx = 200; Int_t ny = 200; TH2F *h = new TH2F("h","test",nx,-3,3,ny,-3,3); TRandom3 r; for (Int_t i=0;i<100000;i++) { h->Fill(r.Gaus(0,1),r.Gaus(0,0.6)); } TCanvas *c1 = new TCanvas("c1"); h->Draw("cont0 colz"); Double_t x,y,z; for (Int_t j=0;j<100000;j++) { x = r.Uniform(-3,3); y = r.Uniform(-3,3); z = h->Interpolate(x,y); } } ```

Thank you Rene for this tip. I am however using 5.18 and if I understand correctly this is implemented in version 5.24. I have tried to upgrade, but my machine is Ubuntu 9.10 and it seems to be problematic to get 5.24 to run under this. Do you (or anyone else!) have an idea how I can solve this interpolation problem in 5.18?

Regards,
Karin

You should have installed version 5.25/04 and not 5.24. Version 5.24 or older cannot run on the latest Ubuntu systems.

Rene