使用二次函数的最高(最低)点和任意另外一点,绘制函数图像。
用python实现
以这个函数图像为例
已知二次函数的顶点和另一个非顶点,求函数方程式
可采用解析式方法进行求解
按此原理对a,k进行设定和计算
下面参数中toplowest为最高(最低)点,point为另一非最高(最低)点
def rate_change_with_time(time):
toplowest_x = 2
toplowest_y = 1
point_x = 4
point_y = 9
a = (point_y-toplowest_y)/((point_x-toplowest_x)**2)
k = toplowest_y
rate = a*((time-toplowest_x)**2)+k
return rate
import numpy as np
import matplotlib.pyplot as plt
t = 10
y = []
for i in np.arange(0, t, 0.1):
y.append(rate_change_with_time(i))
plt.title('transition rate over time')
plt.xlabel('time')
plt.ylabel('rate')
x=np.linspace(0,t,(t)*10)
s1 = "rate" # 注释文字
s2 = "^" # 折线图上每个点的形状
plt.plot(x,y,'-{}'.format(s2),label=s1)