I’m a little sad, because it seems like we don’t have any packages for solving nonlinear equations (not odes, not pdes) on a domain range. An equivalent function in the MATLAB world is
vpasolve() in which I can feed it a vector of functions, and I can specify the range in which the solution is. The problem here is that NLSolve.jl cannot specify ranges, and the functions I feed it depend on other functions with things like square roots and when I start introducing complex numbers the solver breaks. I seemingly also can’t use JuMP.jl, as the functions I am using can’t accept the abstract datatype that
@objective() imposes on the function I feed it.
Here is my example. I am trying to solve for an adiabatic flame temperature, and I have enthalpy and equilibrium constant table lookup functions. My setup is thus:
kpc_lhs(T) = kp(10,T)/kp(9,T); # Eq. 1 kph_lhs(T) = kp(4,T); # Eq. 3 kpc_rhs(a,b) = a / ( (4-a)*sqrt(5.475-0.5*(a+b)) ); # Eq. 2 kph_rhs(a,b) = b / ( (5-a)*sqrt(5.475-0.5*(a+b)) ); # Eq. 4 ΔH(a,b,T) = a*(hs("CO2",T)-94.054) + (4-a)*(hs("CO",T)-26.42) + b*(hs("H2O",T)-57.798) + (5-a)*hs("H2",T) + (5.475-0.5*a-0.5*b)*hs("O2",T) + 28.1209*hs("N2",T) + 30.065; # = 0 kpc(a,b,T) = kpc_lhs(Tf) - kpc_rhs(a,b) # Eq. 1 - Eq. 2 = 0 kph(a,b,c) = kph_lhs(Tf) - kph_rhs(a,b); # Eq. 3 - Eq. 4 = 0
where I need to solve
T. In the past I tried using Roots.jl, and solving one of the k equations for
b, but this gets complex quickly when doing this over and over. As you can see,
a+b needs to remain smaller than 10.95 per the formulation in Eq. 2 and Eq. 4. I know their values are between 1 and 5, so I need my solver to stay within these bounds.
I can’t be the only one who needs constraints in problems like these, and as much as I’d like to turn towards something like JuMP, I am unable to due to my enthalpy lookup functions having no clue what to do with what it places in for
T. Moreover, JuMP is not a solving library but an optimization library. I’m hoping I’ve just missed a package out there, if anyone knows of something capable of performing this.