from scipy import *
from pylab import *
from math import *
import numpy as np
file=open("/home/mike/Code/chse.txt").readlines()
for i in xrange(len(file)):
file[i]=file[i].split()
for i in range(len(file)):
for j in range(len(file[i])):
file[i][j]=float(file[i][j])
x = range(len(file))
mx = [file[F][3] for F in range(len(file))]
lx = [file[p][2] for p in range(len(file))]
sx = [file[p][1] for p in range(len(file))]
x = np.array([x])
mx = np.array([mx])
lx = np.array([lx])
lm = lx * mx
R0 = np.sum(lm)
G = (np.sum(x*lx*mx))/R0
def Rest(x, lx, mx)
return (log(R0))/G
r_list=[]
def calc_error(lm, r, x):
return 1. - np.sum(lm*np.e**(-r*x))
def bisect(lm, mx, x):
error = calc_error(lm, Rest(x,lx,mx), x)
if error>=0:
Rlow = Rest(x,lx,mx) - 1.
Rhigh = Rest(x,lx,mx)
else:
Rhigh = Rest(x,lx,mx) + 1.
Rlow = Rest(x,lx,mx)
while np.abs(error) > 0.001:
Rguess = ((Rhigh + Rlow) / 2.)
error = calc_error(bl, Rguess, x)
if error >=0:
Rhigh = Rguess
else:
Rlow = Rguess
def fecund(mx,f):
return(bx/bx[15])*f
for f in range(60):
nmx=fecund(mx,f)
Rest=Rest(x,lx,nmx)
r_list.append(bisect(lm,nmx,x))
plot_data=[]
for years in range(60):
plot_data.append([years, r_list[years]])
Traceback (most recent call last):
File "", line 1, in <module>
File "/tmp/tmpM2tBTc/___code___.py", line 8, in <module>
file=open("/home/mike/Code/chse.txt").readlines()
IOError: [Errno 2] No such file or directory: '/home/mike/Code/chse.txt'