Solving for unknowns

61 views Asked by At
import numpy as np
import scipy 
from scipy.optimize import newton
import sympy
from sympy import diff
from sympy import Symbol

alpha = Symbol('alpha')
beta = Symbol('beta')
delta = Symbol('delta')

kss = ((((1/beta)+ alpha * delta - 1)/(1-alpha)) + delta)**alpha
css = (((1/beta)+ alpha * delta - 1)/(1-alpha))*kss
xss = [css,css,kss]

param = [alpha,beta,delta]

res = diff([xss],alpha, beta, delta)
eps = 0.0001 * np.absolute(css)
x1 = [css+eps,css,kss]
res1 = foc(x1,param)
b1 = (res1 - res)/eps
yss = [css,css+eps,kss]
res2 = foc(yss,param)
b2 = (res2-res)/eps
eps1 = 0.0001 * abs(kss)
zss = [css,css,kss+eps1]
res3 = foc(zss,param)
b3 = (res3-res)/eps1

print b1, b2, b3

Does anyone know how to debug this?

1

There are 1 answers

0
Jake0x32 On

Normally your code should be improved in the following ways:

  1. use module and dot to indicate your function applied, for example abs should be np.abs

  2. You should figure out what kind of data structures you want to use: list or np.array? They are different. Simply xss = [css,css,kss] creates a list which cannot be used for abs directly.

  3. Use import pdb; pdb.set_trace() to debug, here is a tutorial.