- Author:
- Shelley Fong <sfon036@UoA.auckland.ac.nz>
- Date:
- 2022-05-11 16:50:16+12:00
- Desc:
- Updating version with Yang05 modifications
- Permanent Source URI:
- https://models.physiomeproject.org/workspace/818/rawfile/ad3c1a3c060ce9500f56f3fae9cc78aa3db44a39/parameter_finder/k1k6_fitting/k1k6_fitting.py
# Fit a curve to time-varying k1/k6 parameters for the Hai Murphy smooth muscle contraction model
import numpy as np
import matplotlib.pyplot as plt
import scipy.optimize
def monoExp(t, m, q):
return m * np.exp(-q * t)
time = np.linspace(0,60,2000)
k1_OG = [0.55*1 if t < 5 else 0.3 for t in time]
p0 = (1, 1) # start with values near those we expect
params, cv = scipy.optimize.curve_fit(monoExp, time, k1_OG, p0, maxfev=2000, ftol=1e-4) # (function, xdata, ydata, p_IC)
m, q = params
k_opt = monoExp(time, m, q)
print(f"kfit = {m} * e^({q} * t)")
# manual plots
k_test = monoExp(time, 1.66, 0.09995)
plt.figure
plt.plot(time, k1_OG)
plt.plot(time, k_opt)
plt.plot(time, k_test)
plt.legend(['original','fit','manual test against upper = 0.55*3'])
plt.show()