This commit is contained in:
lwj
2025-06-13 23:08:32 +08:00
parent e5729d884f
commit 3fc9330dd6
3 changed files with 28 additions and 17 deletions

12
89-3.py
View File

@@ -1,7 +1,4 @@
x = [19,25,31,38,44]
y = [19.0,32.3,49.0,73.3,97.8]
# 列主元高斯消元法
def SovleRowMain(A,b):
ks = 0.00000001
@@ -61,8 +58,15 @@ def LeastSquares(list_x,list_y,n):
for j in range(n+1):
tmp.append(x_n[i+j])
A.append(tmp)
return SovleRowMain(A,b)
print("A:", A)
print("b:", b)
result = SovleRowMain(A, b)
print("result:", result)
return result
#把x和y换成题干的数值###################
x = [19,25,31,38,44]
y = [19.0,32.3,49.0,73.3,97.8]
if __name__ == "__main__":
x_square = [i**2 for i in x]
coeff = LeastSquares(x_square, y, 1)