我是靠谱客的博主 凶狠黑裤,这篇文章主要介绍基于python对密立根油滴实验数据处理改进基于python对密立根油滴实验数据处理改进,现在分享给大家,希望可以做个参考。

基于python对密立根油滴实验数据处理改进

近似最大公约数

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import math ac=1.34 def accuracy(x, y): return math.fabs(x - y) < ac def gcd(x, y): if accuracy(x, 0): return y if accuracy(y, 0): return x return gcd(y, x%y) b=[3.2,3.2,6.4,4.8,8.0,9.6] a=[1.60217663410,2*1.60217663410,3*1.60217663410,4*1.60217663410,5*1.60217663410,6*1.60217663410] c=[7.88,6.25,3.11,3.18,4.57,6.29] d=[9.36,3.16,3.41,10.78,4.90,3.11] x=[7.88,6.25,3.11,3.18,4.57,6.29] f=[2*1.60217663410,100,3*1.60217663410,4*1.60217663410,5*1.60217663410,6*1.60217663410] n=6 e=2*1.60217663410 for j in range(0,10): for i in range(1,n): e=gcd(e, a[i]) for i in range(1,n): if(a[i]%e>10): del a[i] n=n-1 print(e)

梯度下降拟合“倒过来验证”方法

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import numpy as np import matplotlib.pyplot as plt N = 6 x = np.array([5,4,2,2,3,4]).reshape(N,1) y = np.array([7.88,6.25,3.11,3.18,4.57,6.29]).reshape(N,1) plt.scatter(x, y) ones = np.ones((N, 1)) x = np.hstack((x, ones)) def CostGradient(theta, x, y): diff = np.dot(x, theta) - y gradient = (1./N)*(np.dot(np.transpose(x), diff)) return gradient def Iteration(): alpha = 0.001 theta = np.array([1.6, 0]).reshape(2, 1) gradient = CostGradient(theta, x, y) epsilon = 0.001 while np.linalg.norm(gradient) > epsilon: theta = theta - alpha * gradient gradient = CostGradient(theta, x, y) return theta Right_theta = Iteration() print('下降后e值为:') print('e=',Right_theta[0][0]) print('拟合函数为:') print('y=',Right_theta[0][0],'x') x1 = np.linspace(1, 10, 100) y1 = Right_theta[0]*x1 + Right_theta[1] plt.plot(x1, y1) plt.show()

最后

以上就是凶狠黑裤最近收集整理的关于基于python对密立根油滴实验数据处理改进基于python对密立根油滴实验数据处理改进的全部内容,更多相关基于python对密立根油滴实验数据处理改进基于python对密立根油滴实验数据处理改进内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(45)

评论列表共有 0 条评论

立即
投稿
返回
顶部