CAMB python convergence power spectrum code

In summary, the conversation is about understanding a python CAMB code for an integration over chi using numpy and scipy libraries. The conversation focuses on the usage of numpy.dot and scipy.integrate.quad functions in the code and how they contribute to the integration process. An example script is also provided to demonstrate the accuracy of using the dot product method for integration. The conversation ends with a question about the name and workings of this method.
  • #1
sunrah
199
22
I'm trying to understand this python CAMB code: http://camb.readthedocs.io/en/latest/CAMBdemo.html
Scroll down to In[29] and In[30] to see it.

It's an integration over chi (comoving distance), yet scipy.integrate.quad is not called. It seems that the fun stuff happens in the last for-loop in In[30], where they use numpy.dot to take dot product of two arrays. What's going on here? The first array is Delta-Chi (see In[29]) and the second is simply the integrand. So how is this integration? Thanks
 
Technology news on Phys.org
  • #2
I'v been messing around with this and found something interesting:

Python:
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import quad

xmax = 10
N = 1000
xx = np.linspace(0,xmax,N)

dx = (xx[2:] - xx[:-2])/2
xx = xx[1:-1]
Nx = len(xx)
yy1 = np.arange(0,Nx, dtype=np.float64)
yy2 = []

f = lambda z: z**3

for ix, x in enumerate(xx):
    foo = np.linspace(min(xx),x,N-2)**3
    yy1[ix] = np.dot(dx, foo)
    yy2.append(quad(f,0,x)[0])

plt.plot(xx,yy1,label='dot')
plt.plot(xx,yy2,label='quad')

If you run this script you'll find pretty good agreement between the integration via quad and integration using the dot product of dx and integrand. The value of N controls accuracy, with N>1000 not producing much noticeable difference. But why does this work? What is this method called thanks
 

1. What is the CAMB python convergence power spectrum code used for?

The CAMB python convergence power spectrum code is used to calculate the power spectrum of gravitational lensing convergence in cosmological models. It is often used in conjunction with other cosmological codes to study the large-scale structure of the universe.

2. How accurate is the CAMB python convergence power spectrum code?

The accuracy of the CAMB python convergence power spectrum code depends on various factors such as the input cosmological parameters and the precision of the numerical methods used. However, it has been extensively tested and validated against other codes, and is known to produce accurate results.

3. Can the CAMB python convergence power spectrum code be used for non-cosmological simulations?

No, the CAMB python convergence power spectrum code is specifically designed for cosmological simulations and cannot be used for other types of simulations. It relies on cosmological parameters and equations to calculate the power spectrum of gravitational lensing convergence.

4. Is the CAMB python convergence power spectrum code open-source?

Yes, the CAMB python convergence power spectrum code is open-source and freely available for anyone to use. It is maintained by a team of developers and is constantly updated to include the latest advancements in cosmology.

5. What programming language is used to write the CAMB python convergence power spectrum code?

The CAMB python convergence power spectrum code is written in the Python programming language. It also relies on other libraries and modules such as NumPy, SciPy, and Matplotlib for its calculations and data visualization.

Similar threads

  • Advanced Physics Homework Help
Replies
6
Views
1K
Replies
1
Views
772
Replies
1
Views
755
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
275
  • Engineering and Comp Sci Homework Help
Replies
23
Views
3K
Replies
5
Views
45K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
Back
Top