python - 求方程的根(在某些点上发散)
问题描述
[在此处输入图片描述][1]
我试图在 VSL [0.001,1] 的范围内求解这个方程以获得 delta_l 的值。我已经尝试使用 python 进行 Fsolve,当我对接近解的 delta l 进行初始猜测时,它给出的结果是 VSL 的值在 [0.001,0.1] 之间。但是,当我改变初始猜测时,我没有获得整个范围的任何解决方案。我还尝试了 scipy root 提供的所有方法,但没有获得任何解决方案。当我尝试使用诸如遗传算法之类的 EA 时,它似乎给出了结果,但由于提供的解决方案范围有限,例如,如果我选择 detla_l 的解决方案范围为 [0.001,0.065],我得到的解决方案是我实际上正在寻找,但如果我扩大范围或缩小范围,我会获得不同的解决方案。理想情况下,我会给出一系列可能落入的解决方案,比如说 [0.0001,0.
由此我了解到该算法没有收敛到方程的解(零 0),我需要一个更好的工具来使其收敛。
如果您有任何想法,我将不胜感激。
#已编辑
事实上,我希望获得的最终解决方案是 VSG。我将首先通过求解上述方程获得 delta_l 值,然后从以下方程计算 VSG。[![在此处输入图像描述][2]][2]
下图是一个参考,我需要用我的代码重现相同的图。[![在此处输入图像描述][3]][3]
这是我生成的图表。[![在此处输入图像描述][4]][4]
我写的代码如下。主要问题是我需要指定 (delta_l) 的解决方案范围以获得所需的结果,对于我的情况,我在这里输入 [0.001,0.065] 但我不应该缩小它,因为我不知道另一个解决方案情况(不同的数据)而不是我会提出一个可接受的范围,比如说 [0.0001,0.2] 并且仍然希望得到类似的结果,但事实并非如此。
import pygad
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import fsolve
import math
D= 0.06 ### Diameter (m)
ROL= 997.9 #### Density liquid Kg/m3
ROG= 1.2 ##### density gas kg/m3
UL= 1.1*(10**(-3))### viscosit Pa.S
UG= 0.000018 ### viscosit Pa.S
G= 9.81 # gravitational acceleration m/s2
sigma= 0.06 #### Interfacial tension N/m
SL=3.14*D
### constants
list_of_derivatives=[]
list_of_interfacial_tension=[]
list_of_interfacial_tension_gas=[]
list_of_VSG=[] ###### main values we are looking for
alpha= 20 #### inclination from horizontal Degrees
list_of_liquid_velocities_VSL= np.linspace(0.001,1,80) #va
##################### barneaaaaaa ##############
for VSL in list_of_liquid_velocities_VSL:
AL=3.14*(D**2)*(0.01-0.01**2)
DL=4*AL/SL
A=3.14*(0.5*D)**2
VL=VSL*A/AL
if (D*ROL*VSL/(UL))<2300:
n=1
CL=16
m=0.2
CG=0.046
else:
n=0.2
CL=0.046
m=0.2
CG=0.046
desired_output = 0
def fitness_func(x,x_idx):
derivative = ((G*(ROL-ROG)*D*math.sin(alpha*3.14/180)*((1-2*x)**2-2*(x-x**2)))-((CL/16)*ROL*((D*ROL/UL)**(-n))*(VSL**(2-n))*(((x-x**2)+(1-2*x)**2)/(x-x**2)**3)))
fitness = (1/np.abs(derivative - desired_output))
return fitness
fitness_function = fitness_func
num_generations = 100
num_parents_mating = 4
sol_per_pop = 8
num_genes = 1
init_range_low = 0.001
init_range_high = 0.101
parent_selection_type = "sss"
keep_parents = 1
crossover_type = "single_point"
mutation_type = "random"
mutation_percent_genes = 20
gene_space = [{'low': 0.001, 'high': 0.065}]
ga_instance = pygad.GA(num_generations=num_generations,
num_parents_mating=num_parents_mating,
fitness_func=fitness_function,
sol_per_pop=sol_per_pop,
num_genes=num_genes,
init_range_low=init_range_low,
init_range_high=init_range_high,
parent_selection_type=parent_selection_type,
keep_parents=keep_parents,
crossover_type=crossover_type,
mutation_type=mutation_type,
mutation_percent_genes=mutation_percent_genes,
gene_space= gene_space)
ga_instance.run()
x, solution_fitness, solution_idx = ga_instance.best_solution()
derivative = ((G*(ROL-ROG)*D*np.sin(alpha*3.14/180)*((1-2*x)**2-2*(x-x**2)))-((CL/16)*ROL*((D*ROL/UL)**(-n))*(VSL**(2-n))*(((x-x**2)+(1-2*x)**2)/(x-x**2)**3))) ### should be equal to 0
list_of_derivatives.append(abs(derivative))
interfacial_tenstion=((G*(ROL-ROG)*D*np.sin(alpha*3.14/180)*(x-x**2)*(1-2*x))+((CL/32)*ROL*(D*ROL/UL)**(-n)*VSL**(2-n)*((1-2*x)/(x-x**2)**2))) ### should be equal to interfacial_tension_gas
VSG = (interfacial_tenstion*((1-2*x)**4) /((0.5)*(CG)*((D*ROG/UG)**(-m))*(1+300*x)*(ROG)))**(1/(2-m))
list_of_interfacial_tension.append(interfacial_tenstion)
interfacial_tension_gas= ((((VSG)**(2-m))*(0.5)*(CG)*((D*ROG/UG)**(-m))*(1+300*x)*(ROG))/((1-2*x)**4))/(G*(ROL-ROG)*D) ### this should equal to interfacial_tension
list_of_interfacial_tension_gas.append(interfacial_tension_gas)
list_of_VSG.append(VSG)
VSLexperiment= [0.02,0.06,0.1]
VSGexperiment=[13.94,14.54,19.09]
plt.plot()
plt.xscale("log")
plt.yscale("log")
plt.xlim(1,100)
plt.ylim(0.001,1)
plt.xlabel("VSG", fontsize=9)
plt.ylabel("VSL",fontsize=9)
plt.grid(True, which="both", ls=":", color='0.002', linewidth=0.4)
plt.scatter(VSGexperiment,VSLexperiment, color="Black", linewidth="0.05", label="VsgExperiment")
plt.plot (list_of_VSG,list_of_liquid_velocities_VSL, label='VBarnea', color='blue')
[1]: https://i.stack.imgur.com/L0gLr.png
[2]: https://i.stack.imgur.com/wBXzY.png
[3]: https://i.stack.imgur.com/jRd8I.png
[4]: https://i.stack.imgur.com/8wiOg.png
解决方案
推荐阅读
- python - 使用 gspread 将列表插入谷歌表格
- c - usb_control_msg 返回 -EPIPE
- javascript - 错误:无法将用户序列化到与 Node Js、Passport 和 Mysql 数据库的会话
- javascript - 滚动时如何使用jQuery显示/隐藏div?
- css - 如何从角度的外部包中覆盖!重要样式
- regex - VS Code:如何将片段占位符从 camelCase 转换为 SCREAMING_SNAKE_CASE?
- python - Can't use search feature in datatables server-side processing with django-datatables-view
- c# - C# ODataQueryOptions with EF6 navigation property filters. System.ArgumentNullException : Value cannot be null. Parameter name: type
- javascript - 如何在弹出窗口中添加下一个按钮?
- stm32 - STM32 wake up from standby by WKUP pin rising edge