1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 测量平均值 残差 标准列误差 算术平均测量列误差数据可视化

测量平均值 残差 标准列误差 算术平均测量列误差数据可视化

时间:2020-08-09 05:04:05

相关推荐

测量平均值 残差 标准列误差 算术平均测量列误差数据可视化

python算法

需要导入第三方库numpy,pandas,matplotlib数据分析常用库

import numpy as npimport matplotlib.pyplot as pltdef avg(list_x):#求平均值avg_x= sum(list_x)/len(list_x)return avg_xdef residual(list_x):#求残差list1 = []#定义列表length =len(list_x)#计算长度for i in range(0,length):list1.append(list_x[i]-avg(list_x))#return list1def standError(list_x):#求标准列误差,算术平均标准列误差length = len(list_x)sum = 0for i in range(0,length):sum += list_x[i]**2stE = np.sqrt(sum/(length-1))avg_stE = np.sqrt(sum/(length*(length- 1)))return stE,avg_stEflag=1while (flag==1):test_x = input("请输入n个数据,每个数据用空格隔开: ").split(" ")##依据空格,分片成列表test_x = list(map(int,test_x))#将字符列表转化为数值列表print("该组数据的平均值为: ", avg(test_x))rs =residual(test_x)print("该组数据的残差为: ",rs)sE = np.round(standError(rs),5)print("该组数据的列标准误差和算术平均标准误差为: ",sE)count = len(test_x)x = np.linspace(1, count, count) # 等差数列,从1到count,count个等差数avg_y = np.logspace(1,1,base=avg(test_x),num=count)#本质avg(test_x)**np.linspace(1,1,count)rs_y = rssE_y =np.logspace(1,1,base=sE[0],num=count)nsE_y=np.logspace(1,1,base=sE[1],num=count)plt.plot(x, avg_y, label='y=avg', color='red', linewidth=2) # 绘图函数,label图的名称,color线条颜色,linewidth线条宽度plt.plot(x, rs_y, label='y=residual', color='blue', linewidth=2)plt.plot(x, sE_y, label='y=standError', color='green', linewidth=2)plt.plot(x, nsE_y, label='y=nstandError', color='black', linewidth=2)plt.xlabel('Times') # x轴的名称plt.ylabel('Vol') # y轴的名称plt.title('Physical measurement error ') # 图的标题plt.legend(loc='right') # 图例位置plt.show()flag=int(input("请输入1或0.输入0退出程序,输入1重新进行数据测试: "))

还想了解其他物理算法?---->>>牛顿环测量曲率半径

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。