TGraph2D Number Error

Increasing the bins does work at first, but when I enter nx = 5 and ny = 5 the curved edges are visible. This is not ideal, since the wavefunction is supposed to be 0 at the edges, and the plot does not support that. Is there any way I can enter the formula for the wavefunction and plot it, without plotting each point individually?

In you exemple what should I plot ? AmpTwo ?

No, the unexpected behavior is on the TGraph2D named WaveFunctionTwo. AmpTwo is fine.

Ok what you get is normal. Look at your data (plot below). WaveFunctionTwo has one line of zero on the edge and then the 2nd line of points is a gaussian parallel to this line of zeros. As you can see the triangles are build from the line of zero point to the 2nd line of non zero. These triangles are null only on the edge as soon as to step away from the edge they are non nul along Z axis. Therefore the bins below these triangles can never been fill with 0 even if you make them very small.

Realise that using the LEGO or SURF option you go from unbinned data to binned dat,

float pi = TMath::Pi();
float L = 100; // m
int nx, ny, n;

float roundval(float var)
{
    float value = (int)(var*100+.5);
    return (float)value/100;
}
float waveFunction2D(float energyLevelx, float energyLevely, float lengthx, float lengthy)
{

   float wave = (2/L) * ( roundval(sin(energyLevelx * (lengthx/L) *pi)) )*( roundval(sin(energyLevely * (lengthy/L) *pi)));
   return wave;
}
float Amplitude2D(float wave)
{
    float amp =  wave * wave;
    return amp;
}

void electrons()
{
    nx=ny=1;
    TGraph2D *WaveFunctionTwo = new TGraph2D();
    WaveFunctionTwo->SetNpx(100);
    WaveFunctionTwo->SetNpy(100);

    int count = 0;
    for (int j = 0; j <= L; j++ )
    {
        for (int k = 0; k <= L; k++)
        {
            WaveFunctionTwo->SetPoint(count, j, k, waveFunction2D(nx, ny, j, k));
            count++;
        }
    }
    WaveFunctionTwo->Draw("P0 TRI");
}

Ohhh ok now I get it. Thanks for your help and patience.

Use the TRI option if you want to stay with unbinned data .

1 Like

Okay, thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.