# Solve constraints don't work properly

So in my previous question, I was trying to find two parameters kV and km for an implicit function using FindFit(FF) command and I did it but the problem is that it takes around an hour to do it. Using EvaluationMonitor on FF, I found that the problem lies in Solve and that FF solves it with "empty" variables and only after that it starts to fit parameters.

kaA = 4.3*10^-7; kaB = 5.6*10^-10; kaW = 6.2*10^-8; nA = 1; nB = 2;
kH = 1; kW = 1; HB = 10^-7; cBWA = 1*10^-3; kV1 = 0.41*10^-3; km1 = 13.1*10^-3;

f1[sB_,H_,kV_,km_]:=(H+kaA) (H+kaB) (H+kaW) (HB+kaW) ((-H+HB) kH+(cBWA (-H+HB) kaW kW)/((H+kaW) (HB+kaW))+(kV (-kaA (H+kaB) nA+H (H+kaA) nB) (km+kV-sB-Sqrt[(km+kV-sB)^2+4 km sB]))/((H+kaA) (H+kaB) (km-kV+sB+Sqrt[(km+kV-sB)^2+4 km sB])))


The f polynomial as well as original model is equal to 0. Using Solve I found solution for H and turned the function to explicit one. I Solved it without the colon :, and it took the same amount of time as FF. After that using FF was WAY faster, because we don't solve it every time, but there was another problem. Some constraints that I wrote are not working in Solve.

poly1[sB_,kV_,km_]:=H/.Solve[f1[sB,H,kV,km]==0&&0<=sB<=1&&kV>0&&km>0,H,PositiveReals,InverseFunctions->True][[1]]


Don't pay attention to the Root, it's okay. The problem is that the constraint non-strict constraints 0<=sB<=1 turns to strict ones 0<sB<1. This is unacceptable because my data for sB contains 0 and 1. Why is this happening?

• Cannot reproduce it in 14.0 on Windows 10. The command H/.Solve[...] is running without any response for a long time. Commented Feb 21 at 8:11
• It really does take a long time, but it works trust me. I doubt that OS have anything to do with that. I added constants from previous question. Did you tried compute it without them? Commented Feb 21 at 8:30
• My comp is not strong though 14.0 under Windows 10 runs on my comp. Commented Feb 21 at 9:00
• You override the constraint by specifying the domain as PositiveReals. To be consistent, the domain should be NonnegativeReals. Or just use either Reals or no domain specification. Commented Feb 24 at 4:43
• It NonnegativeReals gives similar result Root[] if km>0 && sB>0 && kV>0 and won't let me use 0 for sB. Commented Feb 27 at 7:20

ok, so I tried writing constraints like this,

poly1[sB_, kV_, km_] = ha/. Solve[f1[sB,ha,kV,km]==0, ha, NonNegativeReals, InverseFunctions -> True,Assumptions -> kV > 0 && km > 0 && sB >= 0][[1]]


and now everything works as it should and I can set 0 for sB

If one rationalizes the constants, then your equation simplifies:

kaA = 43*10^-8; kaB = 56*10^-11; kaW = 62*10^-9; nA = 1; nB = 2;
kH = 1; kW = 1; HB = 10^-7; cBWA = 1*10^-3; kV1 = 41*10^-5; km1 =
131*10^-4;

f1[sB_, H_, kV_,
km_] := (H + kaA)  (H + kaB)  (H + kaW)  (HB +
kaW)  ((-H +
HB)  kH + (cBWA  (-H + HB)  kaW  kW)/((H + kaW)  (HB +
kaW)) + (kV  (-kaA  (H + kaB)  nA + H  (H + kaA)  nB)  (km +
kV - sB - Sqrt[(km + kV - sB)^2 + 4  km  sB]))/((H +
kaA)  (H + kaB)  (km - kV + sB +
Sqrt[(km + kV - sB)^2 + 4  km  sB])))
f1[sB, H, kV, km] // FullSimplify


Because you want solutions of $$H$$ to be greater than zero, the only part of the equation that matters when you want the function to be zero is

1/10000000 - H + (31 (-1 + 81/(31 + 500000000 H)))/81000 +
((-301 + 12500000000 H (43 + 200000000 H)) (-km - kV - sB + Sqrt[(km + kV - sB)^2 + 4 km sB]))/
(2 (43 + 100000000 H) (7 + 12500000000 H))


And we see that other than $$H$$ the other parameters are in a single form:

-km - kV - sB + Sqrt[(km + kV - sB)^2 + 4 km sB]


So we can just rewrite the function as follows:

f2[H_, x_] := 1/10000000 - H + (31 (-1 + 81/(31 + 500000000 H)))/81000 +
((-301 + 12500000000 H  (43 + 200000000 H))  x)/
(2 (43 + 100000000 H) (7 + 12500000000 H))


Setting $$x$$ to any positive value easily results in a value of $$H$$ that satisfies f2[H, x]==0:

Solve[f2[H, 1/10] == 0, H, PositiveReals] // N
(* {{H -> 5.45147*10^-10}, {H -> 0.0996172}} *)

Solve[f2[H, 20] == 0, H, PositiveReals] // N
(* {{H -> 5.58481*10^-10}, {H -> 19.9996}} *)


Given that your original coefficients aren't exact, having

H=-km - kV - sB + Sqrt[(km + kV - sB)^2 + 4 km sB]


appears to be the general solution.