I have a function who I neeed to make to it partial derivatives dependent on a parameter and to use this in another function, and then to solve an ODE system, The function who I need to derivate is anizotropy_energy with respect of theta and phi
import sympy
import numpy as np
from sympy import Symbol, diff, sin, cos
theta = Symbol('theta')
phi = Symbol('phi')
theta_k = Symbol('theta_k')
phi_k = Symbol('phi_k')
def anizotropy_energy(theta, phi, theta_k, phi_k):
u_rx = sin(theta)*sin(phi)
u_ry = sin(theta)*sin(phi)
u_rz = cos(theta)
u_kx = sin(theta_k)*cos(phi_k)
u_ky = sin(theta_k)*sin(phi_k)
u_kz = cos(theta_k)
u_kx*u_rx + u_ky*u_ry + u_kz*u_rz
diff((u_kx*u_rx + u_ky*u_ry + u_kz*u_rz)**2, theta)
I made it with sympy, but I can't use these derrivates in odeint
I have an intermediate function where I a have to add to a structure with theta and phi this derrivates and then to use this function in the main program with Ode
Intermediate function:
import math
import numpy as np
from anisotropy_energy import anizotropy_energy
def thetafunc_anisotropy(alpha,theta,phi, hx, hy, hz, theta_k, phi_k):
return alpha*(hx*np.cos(theta)*np.cos(phi) + hy*np.cos(theta)*np.sin(phi)- \
hz*np.sin(theta) + \
anizotropy_energy(theta, phi, theta_k, phi_k) + \
(-hx*np.sin(phi) + hy*np.cos(phi))
# diff(anizotropy_energy(theta, phi, theta_k, phi_k), phi) )
The main programme:
import matplotlib as mpl
from scipy.integrate import odeint
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import thetafunc_anizotropy
from thetafunc_anizotropy import thetafunc_anisotropy
import phifunc_anizotropy
from phifunc_anizotropy import phifunc_anisotropy
import sympy
def LLG(y, t, alpha, hx, hy, hz, theta_k, phi_k):
theta, phi = y
dydt = [thetafunc_anisotropy(alpha,theta,phi, hx, hy, hz, theta_k, phi_k), thetafunc_anisotropy(alpha,theta,phi, hx, hy, hz, theta_k, phi_k)]
return dydt
alpha = 0.1
H = 1.0
t0 = 60.0*np.pi/180.0
p0 = 0.0*np.pi/180.0
hx = H*np.sin(t0)*np.cos(p0)
hy = H*np.sin(t0)*np.sin(p0)
hz = H*np.cos(t0)
theta_k = 60.0*np.pi/180.0
phi_k = 60.0*np.pi/180.0
y0 = [np.pi, -0*np.pi]
t = np.linspace(0, 1000, 10000)
sol = odeint(LLG, y0, t, args=(alpha,hx, hy, hz, theta_k, phi_k ))
print sol
mpl.rcParams['legend.fontsize'] = 10
#
fig = plt.figure()
ax = fig.gca(projection='3d')
#x = np.sol[:, 0]
#y = sol[:, 1]
#ax.plot(x, y, label='parametric curve')
#ax.legend()
x = np.sin(sol[:, 0])*np.cos(sol[:, 1])
y = np.sin(sol[:, 0])*np.sin(sol[:, 1])
z = np.cos(sol[:, 0])
ax.plot(x, y, z, label='parametric curve')
ax.legend()
#plt.show()
#plt.axes(projection='3d')
#plt.plot(t, sol[:, 0], 'b', label='$\\theta(t)$')
#plt.plot(t,sol[:,1], 'r', label='$\\varphi(t)$')
#
#plt.legend(loc='best')
#plt.xlabel('t')
#
#plt.grid()
#plt.show()
Your error is in anizotropy_energy.py. You have global variables with the same name as function parameters.
In this case you have a global named theta and phi AND function parameters named theta and phi. You must rename one pair of them.
I labeled the function parameters theta and phi to in_theta and in_phi. You should really rename them.
Also, Note that in some places you say anisotropy and some you say anizotropy.
import sympy
import numpy as np
from sympy import Symbol, diff, sin, cos
theta = Symbol('theta')
phi = Symbol('phi')
theta_k = Symbol('theta_k')
phi_k = Symbol('phi_k')
def anizotropy_energy(in_theta, in_phi, theta_k, phi_k):
u_rx = sin(in_theta)*sin(in_phi)
u_ry = sin(in_theta)*sin(in_phi)
u_rz = cos(in_theta)
u_kx = sin(theta_k)*cos(phi_k)
u_ky = sin(theta_k)*sin(phi_k)
u_kz = cos(theta_k)
u_kx*u_rx + u_ky*u_ry + u_kz*u_rz
return diff((u_kx*u_rx + u_ky*u_ry + u_kz*u_rz)**2, theta)
Related
import astropy.io.fits as ap
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d
from scipy.ndimage import gaussian_filter
import math
from scipy.special import sph_harm
from scipy.special import legendre
import scipy.integrate
def legendre(x,n):
leg = legendre(n)
P_n = leg(x)
return P_n
hdu1 = ap.open("magnetogram.fits")
hdu1.info() # so only one hdu list is there in this magnetogram fits file with 360X180
data = hdu1[0].data
#print(data[0:, 359]) # the first run from 0 to 179 and other run from 0 to 359
theta_old = np.arccos(np.linspace(-1, 1, num=180))
theta_new = np.linspace(180*(3.14/180), 0, 180)
Br_new = np.empty((180,360), float) #empty array of the same dimesnion as Br magnetogram
for i in range(0, 360):
f = interp1d(theta_old, data[0:, i], kind="cubic")
Br_new[0:, i] = f(theta_new)
Br_new = gaussian_filter(Br_new, sigma=[2, 2])
print(data.shape, theta_old.shape)
print(Br_new.shape)
print(Br_new)
plt.figure()
#x = theta_old
#y = np.linspace(0, 360, 361)
#Z = data
#plt.imshow(Z, interpolation= "bilinear")
#plt.show()
x_new = (np.linspace(3.14, 0, 181))
y = np.linspace(0, 360, 361)
Z = Br_new
plt.imshow(Z, interpolation= "bilinear")
plt.show()
print("nnn")
CmlCoefficients = []
for l in range(0,3):
#a = []
for m in range(-l,l+1):
freal = lambda Theta, Phi: Br_new[int(Theta), int(Phi)] * math.sin((3.14 / 180) * Theta) *
(np.real(
scipy.special.sph_harm(-m, l, (3.14 / 180) * Phi, (3.14 / 180) * Theta))) # legendre polynomial handle
fimaginary = lambda Theta, Phi: Br_new[int(Theta), int(Phi)] * math.sin((3.14 / 180) * Theta) *
(np.imag(
scipy.special.sph_harm(-m, l, (3.14 / 180) * Phi, (3.14 / 180) * Theta))) # legendre
polynomial handle
answerreal = (scipy.integrate.dblquad(freal, 0, 360, lambda Theta: 0, lambda Theta: 180))
answerimag = (scipy.integrate.dblquad(fimaginary, 0, 360, lambda Theta: 0, lambda Theta: 180))
CmlCoefficients.append((l, m, complex(answerreal[0], answerimag[0])))
print(answerreal,answerimag)
print(CmlCoefficients)
I am trying to integrate over a function F(theta, Phi) where the integrand depends on a 2D array of data of shape (180, 360) in product with some special mathematical function (spherical harmonics). Now the thing is my code works and evaluate the integrals for each value of l and m but the error in the integration is way too much. Say, for l=0 and m=0 value of the integral is -5113.672846048103 and error is 257.68725625979823
Is there any way to reduce the error??
I'm pretty sure you can compute integrals of low-degree spherical harmonics times a trig function on paper and pencil. Ok, maybe with a symbolic integrator like sympy.
Otherwise, do repeated one-dimensional integrals over tge angles using the weights="sin" parameter to quad. But I'm pretty sure paper-and-pencil will be less work here.
I have a complex BVP problem (almost Shrodinger equation). My code works but the solution is completely wrong or just equal to zero. What am I doing wrong?
I also have obtained right solution by Maple, there was no problem. Also I don't understand why there is no problem with plot when it has to be complex-valued function.
import numpy as np
from scipy.integrate import odeint
from scipy.integrate import solve_bvp as bvp
import matplotlib.pyplot as plt
mp = 938.2720813
mn = 939.5654133
mu = (mn + mp)/4
h2m = hbar**2/(2*mu)
V0 = 20
Rv = 1.5
Q0 = 1.5
Rq = 4.5
EIm = 0.3
ERe = 1
V = lambda x : -V0*np.exp(-x/Rv)
Q = lambda x : -Q0*np.exp(-x/Rq)
def fun(x, y):
return np.vstack((y[1], -( Q(x)/ h2m ) - ((ERe + 1j * EIm) *y[0]/ h2m ) + V(x)*y[0]/h2m - (2/y[0])* y[1]))
def bc(ya, yb):
return np.array([ya[0], yb[0]])
x = np.linspace(0, 1000, 10000)
y_a = np.zeros((2, x.size), dtype=np.complex)
# print(x.size)
i = 0
while i < x.size - 1:
i = i + 1
y_a[0, i] = 1000* 1j
y_a[1, i] = 1j
from scipy.integrate import solve_bvp
res_a = solve_bvp(fun, bc, x, y_a)
x_plot = np.linspace(0, 1000, 10000)
y_plot_a = res_a.sol(x_plot)[0]
import matplotlib.pyplot as plt
plt.plot(x_plot, y_plot_a, label='y_a')
plt.legend()
plt.xlabel("x")
plt.ylabel("y")
plt.show()
Upd: I fixed a mistake in the equation.
Result is still wrong. But there is another error - division by zero. How to avoid it? If I choose x = np.linspace(0.1, 1000, 10000) for example it doesn't help.
I'm trying to solve a system of coupled first-order ODEs:
where Tf for this example is considered constant and Q(t) is given. A plot of Q(t) is shown below. The data file used to create the time vs Q plot is available at here.
My Python code for solving this system for the given Q(t) (designated as qheat) is:
import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import solve_ivp
# Data
time, qheat = np.loadtxt('timeq.txt', unpack=True)
# Calculate Temperatures
def tc_dt(t, tc, ts, q):
rc = 1.94
cc = 62.7
return ((ts - tc) / (rc * cc)) + q / cc
def ts_dt(t, tc, ts):
rc = 1.94
ru = 3.08
cs = 4.5
tf = 298.15
return ((tf - ts) / (ru * cs)) - ((ts - tc) / (rc * cs))
def func(t, y):
idx = np.abs(time - t).argmin()
q = qheat[idx]
tcdt = tc_dt(t, y[0], y[1], q)
tsdt = ts_dt(t, y[0], y[1])
return tcdt, tsdt
t0 = time[0]
tf = time[-1]
sol = solve_ivp(func, (t0, tf), (298.15, 298.15), t_eval=time)
# Plot
fig, ax = plt.subplots()
ax.plot(sol.t, sol.y[0], label='tc')
ax.plot(sol.t, sol.y[1], label='ts')
ax.set_xlabel('Time [s]')
ax.set_ylabel('Temperature [K]')
ax.legend(loc='best')
plt.show()
This produces the plot shown below but unfortunately several oscillations occur in the results. Is there a better method to solve this coupled system of ODEs?
Like already said in the comments, it's recommended to interpolate Q. The oscillation typically occurs when trying to solve a stiff ODE system with an explicit method like RK45 (standard for solve_ivp). Since your ODE system seems to be a stiffed one, its further recommended to use a Implicit Runge-Kutta method like 'Radau':
import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import solve_ivp
from scipy.interpolate import interp1d
# Data
time, qheat = np.loadtxt('timeq.txt', unpack=True)
# Interpolate Q
Q = interp1d(time, qheat) # linear spline
# Calculate Temperatures
def tc_dt(t, tc, ts, q):
rc = 1.94
cc = 62.7
return ((ts - tc) / (rc * cc)) + q / cc
def ts_dt(t, tc, ts):
rc = 1.94
ru = 3.08
cs = 4.5
tf = 298.15
return ((tf - ts) / (ru * cs)) - ((ts - tc) / (rc * cs))
def func(t, y):
idx = np.abs(time - t).argmin()
tcdt = tc_dt(t, y[0], y[1], Q(t))
tsdt = ts_dt(t, y[0], y[1])
return tcdt, tsdt
t0 = time[0]
tf = time[-1]
# Note the passed values for rtol and atol.
sol = solve_ivp(func, (t0, tf), (298.15, 298.15), method="Radau", t_eval=time, atol=1e-8, rtol=1e-8)
# Plot
fig, ax = plt.subplots()
ax.plot(sol.t, sol.y[0], label='tc')
ax.plot(sol.t, sol.y[1], label='ts')
ax.set_xlabel('Time [s]')
ax.set_ylabel('Temperature [K]')
ax.legend(loc='best')
plt.show()
gives me:
I finally got a reasonable solution for the system of ODEs by providing the Jacobian matrix to the solver. See below for my working solution.
import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import solve_ivp
from scipy.interpolate import interp1d
# Data
time, qheat = np.loadtxt('timeq.txt', unpack=True)
# Calculate Temperatures
interp_qheat = interp1d(time, qheat)
def tc_dt(t, tc, ts, q):
"""
dTc/dt = (Ts-Tc)/(Rc*Cc) + Q/Cc
"""
rc = 1.94
cc = 62.7
return ((ts - tc) / (rc * cc)) + q / cc
def ts_dt(t, tc, ts):
"""
dTs/dt = (Tf-Ts)/(Ru*Cs) - (Ts-Tc)/(Rc*Cs)
"""
rc = 1.94
ru = 3.08
cs = 4.5
tf = 298.15
return ((tf - ts) / (ru * cs)) - ((ts - tc) / (rc * cs))
def jacobian(t, y):
"""
Given the following system of ODEs
dTc/dt = (Ts-Tc)/(Rc*Cc) + Q/Cc
dTs/dt = (Tf-Ts)/(Ru*Cs) - (Ts-Tc)/(Rc*Cs)
determine the Jacobian matrix of the right-hand side as
Jacobian matrix = [df1/dTc, df2/dTc]
[df1/dTs, df2/dTs]
where
f1 = (Ts-Tc)/(Rc*Cc) + Q/Cc
f2 = (Tf-Ts)/(Ru*Cs) - (Ts-Tc)/(Rc*Cs)
"""
cc = 62.7
cs = 4.5
rc = 1.94
ru = 3.08
jc = np.array([
[-1 / (cc * rc), 1 / (cs * rc)],
[1 / (cc * rc), -1 / (cs * ru) - 1 / (cs * rc)]
])
return jc
def func(t, y):
"""
Right-hand side of the system of ODEs.
"""
q = interp_qheat(t)
tcdt = tc_dt(t, y[0], y[1], q)
tsdt = ts_dt(t, y[0], y[1])
return tcdt, tsdt
t0 = time[0]
tf = time[-1]
sol = solve_ivp(func, (t0, tf), (298.15, 298.15), method='BDF', t_eval=time, jac=jacobian)
# Plot
fig, ax = plt.subplots(tight_layout=True)
ax.plot(sol.t, sol.y[0], label='tc')
ax.plot(sol.t, sol.y[1], label='ts')
ax.set_xlabel('Time [s]')
ax.set_ylabel('Temperature [K]')
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5), frameon=False)
plt.show()
And the generated plot is shown below.
The only advantage to interpolating Q was to speed up the execution of the code by removing the argmin() in the main function. Otherwise, interpolating Q did not improve the results.
am trying to predict the exact solution for the mathieu's equation y"+(lambda - 2qcos(2x))y = 0. I have been able to get five eigenvalues for the equation using numerical approximation and I want to find for each eigenvalues a guessed exact solution. I would be greatfull if someone helps. Thank you. Below is one of the codes for the fourth Eigenvalue
from scipy.integrate import solve_bvp
import numpy as np
import matplotlib.pyplot as plt
Definition of Mathieu's Equation
q = 5.0
def func(x,u,p):
lambd = p[0]
# y'' + (lambda - 2qcos(2x))y = 0
ODE = [u[1],-(lambd - 2.0*q*np.cos(2.0*x))*u[0]]
return np.array(ODE)
Definition of Boundary conditions(BC)
def bc(ua,ub,p):
return np.array([ua[0]-1., ua[1], ub[1]])
A guess solution of the mathieu's Equation
def guess(x):
return np.cos(4*x-6)
Nx = 100
x = np.linspace(0, np.pi, Nx)
u = np.zeros((2,x.size))
u[0] = -x
res = solve_bvp(func, bc, x, u, p=[16], tol=1e-7)
sol = guess(x)
print res.p[0]
x_plot = np.linspace(0, np.pi, Nx)
u_plot = res.sol(x_plot)[0]
plt.plot(x_plot, u_plot, 'r-', label='u')
plt.plot(x, sol, color = 'black', label='Guess')
plt.legend()
plt.xlabel("x")
plt.ylabel("y")
plt.title("Mathieu's Equation for Guess$= \cos(3x) \quad \lambda_4 = %g$" % res.p )
plt.grid()
plt.show()
[Plot of the Fourth Eigenvalues][2]
To compute the first five eigenpairs, thus, pairs of eigenvalues and eigenfunctions, of the Mathieu's equation Y" + (λ − 2q cos(2x))y = 0, on the interval [0, π] with boundary conditions:
y'(0) = 0, and y'(π) = 0 when q = 5.
The solution is normalized so that y(0) = 1. Though all the initial values are known at x = 0, the problem requires finding a value for the parameters that allows the boundary condition y'(π) = 0 to be satisfied.
Therefore the guess or exact solution of Mathieu's equation is cos(k*x) where k ∈ ℕ.
from scipy.integrate import solve_bvp
import numpy as np
import matplotlib.pyplot as plt
q = 5.0
# Definition of Mathieu's Equation
def func(x,u,p):
lambd = p[0]
# y'' + (lambda - 2qcos(2x))y = 0 can be rewritten as u2'= - (lambda - 2qcos(2x))u1
ODE = [u[1],-(lambd - 2.0*q*np.cos(2.0*x))*u[0]]
return np.array(ODE)
# Definition of Boundary conditions(BC)
def bc(ua,ub,p):
return np.array([ua[0]-1., ua[1], ub[1]])
# A guess solution of the mathieu's Equation
def guess(x):
return np.cos(5*x) # for k=5
Nx = 100
x = np.linspace(0, np.pi, Nx)
u = np.zeros((2,x.size))
u[0] = -x # initial guess
res = solve_bvp(func, bc, x, u, p=[20], tol=1e-9)
sol = guess(x)
print res.p[0]
x_plot = np.linspace(0, np.pi, Nx)
u_plot = res.sol(x_plot)[0]
plt.plot(x_plot, u_plot, 'r-', label='u')
plt.plot(x, sol, linestyle='--', color='k', label='Guess')
plt.legend(loc='best')
plt.xlabel("x")
plt.ylabel("y")
plt.title("Mathieu's Equation $\lambda_5 = %g$" % res.p)
plt.grid()
plt.savefig('Eigenpair_5v1.png')
plt.show()
Solution of Mathieu Equation
I have a function as the following
q = 1 / sqrt( ((1+z)**2 * (1+0.01*o_m*z) - z*(2+z)*(1-o_m)) )
h = 5 * log10( (1+z)*q ) + 43.1601
I have experimental answers of above equation and once I must to put some data into above function and solve equation below
chi=(q_exp-q_theo)**2/err**2 # this function is a sigma, sigma chi from z=0 to z=1.4 (in the data file)
z, err and q_exp are in the data file(2.txt). Now I have to choose a range for o_m (0.2 to 0.4) and find in what o_m, the chi function will be minimized.
my code is:
from math import *
from scipy.integrate import quad
min = None
l = None
a = None
b = None
c = 0
def ant(z,om,od):
return 1/sqrt( (1+z)**2 * (1+0.01*o_m*z) - z*(2+z)*o_d )
for o_m in range(20,40,1):
o_d=1-0.01*o_m
with open('2.txt') as fp:
for line in fp:
n = list( map(float, line.split()) )
q = quad(ant,n[0],n[1],args=(o_m,o_d))[0]
h = 5.0 * log10( (1+n[1])*q ) + 43.1601
chi = (n[2]-h)**2 / n[3]**2
c = c + chi
if min is None or min>c:
min = c
l = o_m
print('chi=',q,'o_m=',0.01*l)
n[1],n[2],n[3],n[4] are z1, z2, q_exp and err, respectively in the data file. and z1 and z2 are the integration range.
I need your help and I appreciate your time and your attention.
Please do not rate a negative value. I need your answers.
Here is my understanding of the problem.
First I generate some data by the following code
import numpy as np
from scipy.integrate import quad
from random import random
def boxmuller(x0,sigma):
u1=random()
u2=random()
ll=np.sqrt(-2*np.log(u1))
z0=ll*np.cos(2*np.pi*u2)
z1=ll*np.cos(2*np.pi*u2)
return sigma*z0+x0, sigma*z1+x0
def q_func(z, oM, oD):
den= np.sqrt( (1.0 + z)**2 * (1+0.01 * oM * z) - z * (2+z) * (1-oD) )
return 1.0/den
def h_func(z,q):
out = 5 * np.log10( (1.0 + z) * q ) + .25#43.1601
return out
def q_Int(z1,z2,oM,oD):
out=quad(q_func, z1,z2,args=(oM,oD))
return out
ooMM=0.3
ooDD=1.0-ooMM
dataList=[]
for z in np.linspace(.3,20,60):
z1=.1+.1*z*.01*z**2
z2=z1+3.0+.08+z**2
q=q_Int(z1,z2,ooMM,ooDD)[0]
h=h_func(z,q)
sigma=np.fabs(.01*h)
h=boxmuller(h,sigma)[0]
dataList+=[[z,z1,z2,h,sigma]]
dataList=np.array(dataList)
np.savetxt("data.txt",dataList)
which I would then fit in the following way
import matplotlib
matplotlib.use('Qt5Agg')
from matplotlib import pyplot as plt
import numpy as np
from scipy.integrate import quad
from scipy.optimize import leastsq
def q_func(z, oM, oD):
den= np.sqrt( (1.0 + z)**2 * (1+0.01 * oM * z) - z * (2+z) * (1-oD) )
return 1.0/den
def h_func(z,q):
out = 5 * np.log10( (1.0 + z) * q ) + .25#43.1601
return out
def q_Int(z1,z2,oM,oD):
out=quad(q_func, z1,z2,args=(oM,oD))
return out
def residuals(parameters,data):
om,od=parameters
zList=data[:,0]
yList=data[:,3]
errList=data[:,4]
qList=np.fromiter( (q_Int(z1,z2, om,od)[0] for z1,z2 in data[ :,[1,2] ]), np.float)
hList=np.fromiter( (h_func(z,q) for z,q in zip(zList,qList)), np.float)
diffList=np.fromiter( ( (y-h)/e for y,h,e in zip(yList,hList,errList) ), np.float)
return diffList
dataList=np.loadtxt("data.txt")
###fitting
startGuess=[.4,.8]
bestFitValues, cov,info,mesg, ier = leastsq(residuals, startGuess , args=( dataList,),full_output=1)
print bestFitValues,cov
fig=plt.figure()
ax=fig.add_subplot(1,1,1)
ax.plot(dataList[:,0],dataList[:,3],marker='x')
###fitresult
fqList=[q_Int(z1,z2,bestFitValues[0], bestFitValues[1])[0] for z1,z2 in zip(dataList[:,1],dataList[:,2])]
fhList=[h_func(z,q) for z,q in zip(dataList[:,0],fqList)]
ax.plot(dataList[:,0],fhList,marker='+')
plt.show()
giving output
>>[ 0.31703574 0.69572673]
>>[[ 1.38135263e-03 -2.06088258e-04]
>> [ -2.06088258e-04 7.33485166e-05]]
and the graph
Note that for leastsq the covariance matrix is in reduced form and needs to be rescaled.
Unconcsiosely, this question overlap my other question. The correct answer is:
from math import *
import numpy as np
from scipy.integrate import quad
min=l=a=b=chi=None
c=0
z,mo,err=np.genfromtxt('Union2.1_z_dm_err.txt',unpack=True)
def ant(z,o_m): #0.01*o_m is steps of o_m
return 1/sqrt(((1+z)**2*(1+0.01*o_m*z)-z*(2+z)*(1-0.01*o_m)))
for o_m in range(20,40):
c=0
for i in range(len(z)):
q=quad(ant,0,z[i],args=(o_m,))[0] #Integration o to z
h=5*log10((1+z[i])*(299000/70)*q)+25 #function of dL
chi=(mo[i]-h)**2/err[i]**2 #chi^2 test function
c=c+chi
l=o_m
print('chi^2=',c,'Om=',0.01*l,'OD=',1-0.01*l)