From 515714cbf553f3741847bba5eac312c1ce2204ed Mon Sep 17 00:00:00 2001 From: 123 <629825095@qq.com> Date: Tue, 17 Jun 2025 21:07:52 +0800 Subject: [PATCH] 111 --- 按方法整理/非线性方程-牛顿下山法.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/按方法整理/非线性方程-牛顿下山法.py b/按方法整理/非线性方程-牛顿下山法.py index 7170889..c3aeef1 100644 --- a/按方法整理/非线性方程-牛顿下山法.py +++ b/按方法整理/非线性方程-牛顿下山法.py @@ -2,7 +2,7 @@ import math def NewtonDownHillSolve(fx, dfx, x0, err1,err2, N0,min_t): count = 0 - print(f"k={count}, x0={x0}") + print(f"k={count}, x0={x0}\n") x1 = x0 + 1 + err1 while abs(x1 - x0) > err1 or abs(fx(x1)) > err2: t = 1 @@ -12,7 +12,7 @@ def NewtonDownHillSolve(fx, dfx, x0, err1,err2, N0,min_t): print(f"当前点: x0={x0}") while t >= min_t: x1 = x0 - t * fx(x0) / dfx(x0) - print(f"下山: t={t}, x1={x1}, abs(fx(x1))={abs(fx(x1))}, abs(fx(x0))={abs(fx(x0))}") + print(f"下山: t={t}, x1={x1}, fx(x{count+1})={fx(x1)}, fx(x{count})={fx(x0)}") if abs(fx(x1)) < abs(fx(x0)): break t *= 0.5 @@ -21,7 +21,7 @@ def NewtonDownHillSolve(fx, dfx, x0, err1,err2, N0,min_t): return None, -2 # x1 = x0 - fx(x0) / dfx(x0) count += 1 - print(f"k={count}, x{count}={x1},x1-x0={abs(x1-x0)}") + print(f"k={count}, x{count}={x1},x1-x0={abs(x1-x0)}\n") if count > N0: return None, -1 x0 = x1