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

本文探讨了如何使用Python对密立根油滴实验数据进行处理改进,包括运用近似最大公约数和梯度下降拟合的‘倒过来验证’方法,提升数据分析的精度和效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

近似最大公约数

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)

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

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()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值