This commit is contained in:
2025-06-10 14:29:12 +08:00
parent 0d7b89e21d
commit 68eb32f618
15 changed files with 23 additions and 8 deletions

View File

@@ -43,7 +43,7 @@ def SovleRowMain(A,b):
return b
# 最小二乘法拟合
def LeastSquares(list_x,list_y,n):
m = len(list_x)
x_n = []
@@ -63,6 +63,7 @@ def LeastSquares(list_x,list_y,n):
A.append(tmp)
return SovleRowMain(A,b)
# 计算多项式在给定x值上的值
def CalculateY(list_x, coeff):
re = []
for i in range(len(list_x)):
@@ -71,6 +72,7 @@ def CalculateY(list_x, coeff):
re[i] += coeff[j]*list_x[i]**j
return re
# 计算均方根误差
def MeanSquareErr(list_y,list_y_approx):
m = len(list_y)
err = 0
@@ -78,6 +80,7 @@ def MeanSquareErr(list_y,list_y_approx):
err += (list_y[i] - list_y_approx[i])**2
return err**0.5
# 计算最大误差
def MaxErr(list_y,list_y_approx):
m = len(list_y)
err = 0
@@ -86,6 +89,7 @@ def MaxErr(list_y,list_y_approx):
err = abs(list_y[i] - list_y_approx[i])
return err
# 打印拟合方程
def PrintEquation(coeff):
n = len(coeff)
str_ = str(coeff[0]) + "+"