Home | News | Documentation | Download

ODE interpolation

I want write ROOT or c++ code of this python script:

def ode_func(x, t,a):
    return -(3*pow(1+t,-1)*(a-1))*x*((1-x)/(1-2*x+a*x))

sol=lambda a,inits: odeint(ode_func,inits,t,args=(a,)) 

def model(a,inits):
    y = np.ravel(sol(a,inits))
    return interp1d(t, y, kind='cubic')

def integrand(z, omm,a):
    inits=1-omm
    f2= model(a,inits)
    Ez = 1.0/np.sqrt((omm*(1.0+z)**3 + f2(z)))
    return Ez
def integ(z, omm,a):
    integral = integrate.quad(comoving_integrand, 0, z, args=(omm,a))[0]
    return 300000*(1+z)*integral 

first solve ODE , interpolated over interval and then use as integrand function “comoving_integrand” and finally integrate it.

Any suggestions would be greatly appreciated

Hi soroush,

I this this can be done with RDataFrame. I will involve @eguiraud, maybe he knows the answer.

Cheers,
J.

Hi jalpezg
Thank s for the reply.Is it possible I mention @eguiraud for answering or I should change category to ROOTfit?

You do not have to perform any further action :-). I am also inviting @StephanH.

Cheers.

Thanks a lot.

Hi,
I’m afraid this is really a statistics/scientific computation problem. Maybe @moneta can help.

Cheers,
Enrico

Hi,
ROOT is not having any specific code for solving ODE. But there is code to integrate functions, so based on that you could maybe implement the code above in C++.
Otherwise, you can also use th GSL C library, (used internally in ROOT in the MathMore) library, that provides functions to solve ODE systems (see https://www.gnu.org/software/gsl/doc/html/ode-initval.html )

Lorenzo

1 Like

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