import numpy as np
import matplotlib.pyplot as plt
def u(a,c):
solu = (-1/a)*np.exp(-a*c)
return solu
def u_1d(a,c):
solu = np.exp(-a*c)
return solu
def u_2d(a,c):
solu = -a*np.exp(-a*c)
x = np.linspace(0,10,101)
y1 = np.zeros(len(x))
y2 = np.zeros(len(x))
y3 = np.zeros(len(x))
for idx,i in enumerate(x):
y1[idx] = u(1, i)
y2[idx] = u_1d(1, i)
y3[idx] = u_2d(1, i)
plt.plot(x,y1)
plt.plot(x, y2, label=r'$U\prime$')
plt.plot(x, y3, label=r'$U\prime\prime$')
plt.ylabel('U(c)')
plt.xlabel('c')
plt.axhline(u(1,0), color='red', label=r"$\frac{-1}{a}$")
plt.legend();
ANSWER
def ibc(y1, y2, r, k=1):
c1_1 = (1+r)/(2+r)
c1_2 = (y1+(y2/(1+r)))-(k/(1+r))
c1 = c1_1*c1_2
c2_1 = (1+r)/(2+r)
c2_2 = (y1+(y2/(1+r)))+k
c2 = c2_1*c2_2
return c1,c2
x = np.linspace(0,.5,10)
y = np.zeros(len(x))
y1, y2,r = [20,20, .1]
for idx,i in enumerate(x):
ans1, ans2 = ibc(y1,y2,i, k=2)
plt.scatter(ans1,ans2, label='r= {:.2f}'.format(i))
plt.legend()
plt.ylabel(r'$C_2$')
plt.xlabel(r'$C_1$')
x = np.linspace(0,5,6)
y = np.zeros(len(x))
y1, y2,r = [20,20, .25]
for idx,i in enumerate(x):
ans1, ans2 = ibc(y1,y2,r, k=i)
plt.scatter(ans1,ans2, label='k= {}'.format(i))
plt.legend()
plt.ylabel(r'$C_2$')
plt.xlabel(r'$C_1$')