예제 #1
0
def Gauss_quad(a, b, f, N):
    g_1 = lambda v: g(a, b, v)
    from scipy.optimize import root as eqsolver
    vstar = eqsolver(g_1, np.ones(2 * N)).x
    w = vstar[0:N]
    x = vstar[N:]
    return f(x) @ w
예제 #2
0
def ex1(gamma):
    e0 = 1.
    e1 = np.array([1, 2, 1, 2])
    e2 = np.array([3, 1, 3, 1])
    a1 = np.array([1, 1, 1, 1])
    a2 = np.array([1, 1, 1.5, 1.5])
    guess = np.zeros(4)
    obj = lambda var: eq(e0, e1, e2, a1, a2, var, gamma)
    sol = eqsolver(obj, guess)
    return sol.x
예제 #3
0
def steady(tau, alpha, gamma, xi, delta, a, beta, obj1):
    obj = lambda x: obj1(x[0], x[1], x[2], x[3], x[4], tau, alpha, gamma, xi,
                         delta, a, beta)
    sol = eqsolver(obj, np.array([1, 1.5, .1, 1.2, 1])).x
    return sol
예제 #4
0
    expect_2 = f_p(x, 1) * u_p(f(x, 1) - PL(x, Kgrid, Kp[:, 1]))
    expect = .5 * expect_1 + .5 * expect_2
    V = u_p(f(Kgrid[j], l) - x) - beta * expect
    return V


crit, itera = 1, 0
Kp = Kmin * np.ones([nbk, nba])

while crit > epsi:
    Kp_new = np.zeros([nbk, nba])
    R = np.zeros([nbk, nba])
    for j in range(nbk):
        for l in range(2):
            obj_1 = lambda x: g(f, f_p, u_p, PL, Kgrid, Kp, x, j, l)
            Kp_new[j, l] = eqsolver(obj_1, Kp[j, l]).x
            R[j, l] = obj_1(Kp_new[j, l])
    crit = np.max(np.abs(Kp_new - Kp))
    Kp = Kp_new * 1.
    itera = itera + 1

C = np.zeros([nbk, nba])
for i in range(nbk):
    for j in range(nba):
        C[i, j] = f(Kgrid[i], j) - Kp_new[i, j]

from matplotlib import pyplot as plt

plt.figure(1, figsize=(10, 5))
plt.subplot(121)
plt.plot(Kgrid, Kp_new[:, 0])