scientific-programming-exer.../ex_24.py

24 lines
507 B
Python
Raw Normal View History

2018-11-28 16:10:29 +00:00
import numpy as np
import matplotlib.pyplot as plt
X = np.arange(0, 10, 0.01)
K = 100
alpha = 0.15
real_Y = K*np.exp(-alpha * X)
def approx_function_generator(delta, alpha, K):
def f(x):
if(x <= 0):
return K
return (1 - delta*alpha)*f(x - delta)
return f
plt.plot(X, real_Y)
plt.plot(X, [approx_function_generator(2, alpha, K)(x) for x in X])
plt.plot(X, [approx_function_generator(1, alpha, K)(x) for x in X])
plt.plot(X, [approx_function_generator(0.1, alpha, K)(x) for x in X])
plt.show()