dimanche 18 mars 2018

only size-1 arrays in quadpack

I wrote the following code, It has 3 functions, 3 random numbers and one If statement. Running this code gives as error

return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit) TypeError: only size-1 arrays can be converted to Python scalars

I could not understand what the problem is.

import numpy as np from math import * from scipy.integrate import quad from scipy.integrate import odeint

O_m=chi=None
xx=np.array([0.01,0.012,0.014,0.016]) 
yy=np.array([32.95388698,33.87900347,33.84214074,34.11856704])
Cov=[[137,168],[28155,-2217]]

H01 = 70,z0=0, M=1, Omo = 0.32, Odo=0.68,  H0=70
def ant(z,Om,OD):
    return 1/np.sqrt((1+Om*z)-OD)
def dl(n,Om,OD):
    q=quad(ant,0,xx[n],args=(Om,OD))[0]
    h=5*np.log10((1+xx[n])*q)
    fn=(yy[n]-M-h)
    return fn
def c(Om,OD):      #this function just creates a 2*2 matrix
    f_list = []
    for i in range(2):
        f_list.append(dl(i,Om,OD))
    rdag=[f_list]
    rmat=[[f] for f in f_list]
    mm=np.dot(rdag,Cov)
    zz=np.dot(mm,rmat)
    chi_old=np.linalg.det(zz)*0.000001
    return chi_old               
N=100
for i in range (1,N):
        R1=np.random.uniform(0,1,i)
        R2=np.random.uniform(0,1,i)
        def delta():
            sig=0.1
            p=sig*(np.sqrt(-2*np.log(R1))*np.cos(np.radians(R2)))
            return p
        Omn=Omo+delta()
        Odn=1-Omn
        R3=np.random.uniform(0,1,i)
        def L():
            l=np.exp(-0.5*(c(Omn,Odn)-c(Omo,Odo)))
            return l
        if L()>1:                
            chi=c(Omn,Odn)
        print(chi)

I appreciate your help and your attention




Aucun commentaire:

Enregistrer un commentaire