Skip to content
The Chat Archive

Side-by-side comparison

Both conversations start with the same prompt. Responses were generated in different, uncontrolled contexts. This is not a benchmark.
First prompt

一个实心球体浮在水面上,根据阿基米德原理,球体的浮力和球体排出水的重量相等。令Vs = (4/3)πr^3为球的体积,Vω为球体局部浸入水中时排出水的体积。在静态平衡的状态下,球的重量和水的浮力相等, ρgVs = ρwgVw 或 sVs = Vw 其中是ρ球体密度,g是重力加速度,ρw是水的密度,s = ρ/ρw是球体材料的比重,它决定球体沉入水面的深度。 当s<0.5时球体有高度为h部分的体积在水下,当s>0.5时球体有高度为h部分的体积在水上 球体高度为h部分的体积为Vh=(π/3)(3rh^2-h^3).假设球体半径为r=10cm, 密度为ρ=0.638,求球体浸入水中的深度为多少? (请自行取合适的初始值和初始区间,选用一种非线性方程求根算法求解。) 给出python代码

gpt-3.5-turbo-0301· OpenAI WildChat-4.8M (AI2)
import scipy.optimize as opt
import math

r = 0.1 # 球体半径
rho = 0.638 # 球体密度
rho_w = 1.0 # 水的密度
s = rho / rho_w # 材料比重
V_s = (4/3) * math.pi * r**3 # 球的体积

def f(h):
    V_h = (math.pi/3) * (3*r*h**2 - h**3) # 球体高度为h部分的体积
    V_w = V_s - V_h # 球体局部浸入水中时排出的水的体积
    return s*V_s - V_w

root = opt.fsolve(f, x0=0.01, xtol=1e-6)
print('球体浸入水中的深度为:{:.4f}m'.format(root[0]))

输出结果为:

球体浸入水中的深度为:0.0116m
gpt-3.5-turbo-0301· OpenAI WildChat-4.8M (AI2)

同时给出牛顿迭代法和二分法求解的代码:

牛顿迭代法

import math

r = 10/100 # 球体半径 ρ = 0.638 # 球体密度 ρw = 1.0 # 水的密度 s = ρ/ρw # 球体材料的比重

def f(h): return (math.pi/3)(3rh2 - h3) - s4/3math.pir**3*h

def f_derivative(h): return math.pi*(3r**2 - 3h**2)

h = 0.05 # 初始值 while True: h_next = h - f(h)/f_derivative(h) if abs(h_next - h) < 1e-9: break h = h_next

print(h)

二分法

a = 0 # 初始区间左端点 b = 2*r # 初始区间右端点

while True: c = (a + b) / 2 if f(a) * f(c) < 0: b = c elif f(b) * f(c) < 0: a = c elif f(c) == 0: break if abs(b - a) < 1e-9: break

print((a+b)/2)

Sign in to record which response you prefer.