初めてPythonコードを書く。この関数をグラフ化するのに助けが必要です。これは、重複する成長モデル関数です。方程式が正しいと確信しているにもかかわらず、エラーコードを出し続けます。どんな助けでもいただければ幸いです!
from numpy import *
from pylab import *
from scipy import optimize
from scipy.optimize import fsolve
def olgss(x) :
numg = ((1-alpha)*A*x**alpha)/(1+n)
deng = (1+(1/(beta**(sigma)))*(1+alpha*A*x**(alpha-1))**(1-sigma))
olgk = x - numg/deng
return olgk
# Set the parameter values
alpha = .3 # share of capital income in GDP
A = 1.0 # productivity parameter
beta = 0.8 # discount factor
n = 0.01 # rate of growth of population
sigma = 0.9 # intertemporal elasticity of substitution from the utility function
# Set the inital condition
state= 0.2
xt = [] # The x_t valudebuge
# Iterate for a few time steps
nIterates = 10
# Plot lines, showing how the iteration is reflected off of the identity
for n in xrange(nIterates):
xt.append(state)
state = olgss(state)
plot(xrange(nIterates), xt, 'b')
xlabel('Time')
ylabel('k$t$')
title('Time Path of k$t$')
#savefig('OLGTimePath', dpi=100)
show()
エラーは次のとおりです。
Traceback (most recent call last):
File "C:\Users\AChia\Documents\untitled1.py", line 37, in <module>
state = olgss(state)
File "C:\Users\AChia\Documents\untitled1.py", line 14, in olgss
numg = ((1-alpha)*A*x**alpha)/(1+n)
ValueError: negative number cannot be raised to a fractional power