lesgourg / class_public

Public repository of the Cosmic Linear Anisotropy Solving System (master for the most recent version of the standard code; GW_CLASS to include Cosmic Gravitational Wave Background anisotropies; classnet branch for acceleration with neutral networks; ExoCLASS branch for exotic energy injection; class_matter branch for FFTlog)
230 stars 285 forks source link

Large discrepany between derivatives in class vs numpy #284

Closed rgspo closed 5 years ago

rgspo commented 5 years ago

Hi,

I plotted H and H_prime in classy and compared H_prime with the numpy.gradient() function. Qualitatively, both derivatives look the same but there is a huge discrepancy in the order of magnitude (1e20 <-> 1e31) .

H_analytic_derivatives.pdf

Since H_prime is calculated in conformal time and H in physical time, I thought a rescaling with 1/a would fix the problem. But it just made it worse.

Has anyone else encountered the same problem and can help me with it?

Thank you, Rafaela

Stefan-Heimersheim commented 5 years ago

Hi,

I cannot exactly tell what you are doing without your python code but looking at the documentation of np.gradient I think the numpy function (by default) just takes the derivative with respect to the index and not 'time' or anything.

Did you check that you are passing the correct 'x' value (i.e. time / conformal time) to np.gradient?

Cheers, Stefan

rgspo commented 5 years ago

Hi Stefan,

Thank you for your answer. It was exactly what you said, the spacing of my values was not exact. Now, it looks much better.

Cheers, Rafaela