# Unsolvable system of equations - NSolve takes too long to run

I am trying to solve a system of 6 equations. Here is my input values:

ClearAll["Global*"]
kB = 1.380649*10^-23;
absTemp = 298.15;
beta = 1/(kB*absTemp);
eps0 = 8.8541878128*10^(-12);
eps = 78.304;
f = 96485.33212;
e = 1.60217663*10^(-19);
nA = 6.02214076*10^(23);
k0 = 10^(-9.8);
rhoBbar = 1*nA;
rhoCbar = 1*nA;
rhoDbar = 1*nA;
vA = 1.6*10^-30;
vB = 1.6*10^-30;
vC = 2.48*10^-29;
vD = 2.48*10^-29;
vBb = {8.6}*10^-29;
vBnb = 5*vBb;
vCb = 1*10^-28;
u1 = u2 = u3 = -1.5/beta;
vW = 0.03*10^-27;
dStern = 1000*10^(-12);
pSite = 0.5*nA;


The equations:

c = -((2*eps*eps0)/(e^2*beta)) {(*(10^(-14)/rhoDbar) +*)
rhoBbar + rhoCbar + rhoDbar};
eqn1Squared = (-2*pBnb - 2*pBb + pC + pSiO)^2 == (2*eps*eps0)/(
beta*e^2) {(*10^(-14)/rhoDbar Exp[beta*(-e*phi0 +vD*osmP0)]+*)
rhoBbar*Exp[beta*(-2*e*phi0 - vB*osmP0)] +
rhoCbar*Exp[beta*(e*phi0 - vC*osmP0)] +
rhoDbar*Exp[beta*(e*phi0 - vD*osmP0)]} + c;
eqn2 = pSiO ==
pSite*(k0*rhoDbar*Exp[beta*(e*phi0 - vD*osmP0)])/(
10^(-14) + k0*rhoDbar*Exp[beta*(e*phi0 - vD*osmP0)]);
eqn3 = (pBnb - pC)/(pSiO - pBnb - 2*pBb) ==
Exp[-beta*(u1 + 2*e*phi0 + osmP0*vBnb)];
eqn4 = (Sqrt[2]*pBb)/(pSiO - pBnb - 2*pBb) ==
Exp[-0.5*beta*(u3 + 2*e*phi0 + osmP0*vBb)];
eqn5 = pC/(pBnb - pC) == Exp[beta*(u1 - u2 + e*phi0 - osmP0*vCb)];
eqn6 = osmP0 == -(1/(beta*vW))*
Log[(1(*-(10^(-14)/rhoDbar) Exp[beta*(-e*phi0 +vD*osmP0)]*vA*)-
pBb*vBb/dStern - pBnb*vBnb/dStern - pC*vCb/dStern -
rhoDbar*Exp[beta*(e*phi0 - vD*osmP0)]*vD)/(1(*-(10^(-14)/
rhoDbar) *vA*)- rhoBbar*vB - rhoCbar*vC - rhoDbar*vD)];


To solve this set of equations, I first reduce the system of 6 equations (eqn1Squared, eqn2, eqn3, eqn4, eqn5, eqn6) to a system of 2 equation (eqn1 and eqn6):

solution2345 = Solve[{eqn2, eqn3, eqn4, eqn5}, {pSiO, pBnb, pBb, pC}];
eqns16Squared = {eqn1Squared, eqn6} /. solution2345[[1]];


Then, I use NSolve to solve eqn1Squared and eqn6 together:

simplified = Simplify[eqns16Squared];
solution16Squared = NSolve[simplified, {phi0, osmP0}];


But the code takes forever to run, and I have never been able to get any results so far. I also tried rationalize the system of 2 equations (eqn1Squared and eqn6) before solving:

rationalized = eqns16Squared // Rationalize[#, 0] &;
solution16Squared = NSolve[rationalized, {phi0, osmP0}];


However, the code also takes forever to run, and it will return this error:

PolynomialGCD::lrgexp

I have taken a look at the final sets of equations (eqns16Squared), and I notice the exponents are in extreme values. I suspect that this is causing the code to take forever to run. May I know is there anyway to simplify my current system of equations to facilitate the solving process?

• Looks like a minor scrape-n-paste issue. If I scrape-and-paste-and-evaluate I see eqn1Squared but no eqn1 and eqns16 but no eqns16squared The second one I can guess what to do, the first is less certain.
– Bill
Commented Sep 24, 2023 at 14:09
• @Bill I had a typo when I typed my question, everything had been corrected for eqn1Squared and eqns16Squared. eqn1 is the first equation and eqns16 is the system of equations with first and sixth equations. I named them as eqn1 and eqns16 intially, and later on, I changed the names to eqn1Squared and eqns16Squared because I squared both sides of eqn1`. Commented Sep 24, 2023 at 15:03
• You appear to be using List brackets in place of parentheses (e.g., definitions of vBb, c, eqn1Squared). Don't do that. Don't wait until the end to Rationalize. Rationalize early and do any numeric calculations with arbitrary precision (specify WorkingPrecision) rather than machine precision. Commented Sep 24, 2023 at 19:37