import json from math import exp ambient = 25 temperature = 45.0 h = 0.5 rate = 0.5 trajectory = [temperature] for _ in range(4): # Newton 冷却定律:温度变化率与当前温差成正比,方向指向环境温度。 derivative = -rate * (temperature - ambient) temperature += h * derivative trajectory.append(temperature) exact = ambient + (trajectory[0] - ambient) * exp(-rate * 4 * h) assert all(ambient < b < a for a, b in zip(trajectory, trajectory[1:])) assert abs(temperature - exact) < 1.1 result = {"trajectory": trajectory, "exact_final": exact, "absolute_error": abs(temperature - exact)} print("LAB_RESULT " + json.dumps(result, ensure_ascii=False))