编写程序,分别用二分法及Newton-Raphson迭代法求解RK方程,实现计算摩尔体积的功能。输入有临界压力Pc、临界温度Tc、温度T、及压力p。自行选择初始值。误差不超过0.01cm^3*mol^-1
时间: 2024-05-05 14:15:23 浏览: 19
二分法求解RK方程:
```python
def moore_volume(Pc, Tc, T, P):
a = 0.42748 * R ** 2 * Tc ** 2 / Pc
b = 0.08664 * R * Tc / Pc
m = 0.480 + 1.574 * omega - 0.176 * omega ** 2
k = 0.37464 + 1.54226 * omega - 0.26992 * omega ** 2
alpha = (1 + k * (1 - (T / Tc) ** 0.5)) ** 2
a_alpha = a * alpha
b_P = b * P
v_guess_low = R * T / P
v_guess_high = 10 * b_P # 自行选择初始值
while True:
v_guess = (v_guess_low + v_guess_high) / 2
f = P - R * T / (v_guess - b_P) + a_alpha / (v_guess ** 2 + 2 * v_guess * b_P - b_P ** 2)
if abs(f) < 0.01:
return v_guess
elif f > 0:
v_guess_low = v_guess
else:
v_guess_high = v_guess
```
Newton-Raphson迭代法求解RK方程:
```python
def moore_volume(Pc, Tc, T, P):
a = 0.42748 * R ** 2 * Tc ** 2 / Pc
b = 0.08664 * R * Tc / Pc
m = 0.480 + 1.574 * omega - 0.176 * omega ** 2
k = 0.37464 + 1.54226 * omega - 0.26992 * omega ** 2
alpha = (1 + k * (1 - (T / Tc) ** 0.5)) ** 2
a_alpha = a * alpha
b_P = b * P
v_guess = R * T / P # 自行选择初始值
while True:
f = P - R * T / (v_guess - b_P) + a_alpha / (v_guess ** 2 + 2 * v_guess * b_P - b_P ** 2)
df = R * T / (v_guess - b_P) ** 2 + 2 * a_alpha * (b_P - v_guess) / (v_guess ** 2 + 2 * v_guess * b_P - b_P ** 2) ** 2
v_guess -= f / df
if abs(f) < 0.01:
return v_guess
```
其中,R为气体常数,omega为偏差因子,可以根据所求物质的性质查找相应值。
相关推荐
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)