I would like to solve a system of 9 nonlinear equations, with the constraints on all 9 variables to be that they are nonnegative.
My code is below.
with(Optimization);
restart;
eq1 := 531062-S/(70*365)-(.187*(1/365))*(H+C+C1+C2)*S/N = 0;
eq2 := (4/365*(T+C))*S/N-(.187*(1/365))*(H+C+C1+C2)*T/N-(1/(70*365)+1/(5*365))*T = 0;
eq3 := (.187*(1/365))*(H+C+C1+C2)*S/N-(4/365)(T+C)*H/N-(1/(70*365)+1/(4*365))*H = 0;
eq4 := (.187*(1/365))*(H+C+C1+C2)*T/N+(4/365*(T+C))*H/N-(1/(70*365)+3/(8*365)+.2*(1/365)+.1)*C = 0;
eq5 := .1*C-(1/(70*365)+1/(4*365)+1/60+.5)*C1 = 0;
eq6 := (1/60)*C1-(1/(70*365)+1/(4*365)+1/210+.5)*C2 = 0;
eq7 := .5*C1-(1/(70*365)+1/60+0.1e-2)*CT1 = 0;
eq8 := .5*C2-(1/(70*365)+1/210+(1/9)*(0.1e-2*7))*CT2+(1/60)*CT1 = 0;
eq9 := N-S-T-H-C-C1-C2-CT1-CT2 = 0;
soln := solve({eq1, eq2, eq3, eq4, eq5, eq6, eq7, eq8, eq9}, {C, C1, C2, CT1, CT2, H, N, S, T}, assume = nonnegative);
The 9 equations are OK in syntax and I am getting a bunch of solutions, but they are ignoring my condition of assume = nonnegative
I am getting negative values for $S$, in some of the solution sets. How to fix this?
solve is not part of the Optimization package (actually the restart nullifies the effect of the with(Optimization) anyway). assume=nonnegative is not one of its options. One thing you can do is this:
$$\eqalign{Sols &:= \left\{ \left\{ C= 0.,{\it C1}= 0.,{\it C2}= 0.,{\it CT1}= 0.,{ \it CT2}= 0.,H= 0.,N= 1.356863410 \; 10^{10},S= 1.356863410\; 10^{10},T= 0. \right\} ,\right.\cr & \left.\left\{ C= 0.,{\it C1}= 0.,{\it C2}= 0.,{\it CT1}= 0., {\it CT2}= 0.,H= 0.,N= 2.532811699 \; 10^{11},S= 1.356863410\; 10^{10}, T= 2.397125358 \; 10^{11}\right\} \right\}\cr} $$
EDIT: Claude has a good point. Converting the floats to rationals (before constructing the equations), we get two rational solutions $${C = 0, C1 = 0, C2 = 0, CT1 = 0, CT2 = 0, H = 0, N = 13568634100, S = 13568634100, T = 0}$$ and $${C = 0, C1 = 0, C2 = 0, CT1 = 0, CT2 = 0, H = 0, N = 759843509600/3, S = 13568634100, T = 719137607300/3}$$ and two depending on RootOf a polynomial, one quadratic and one septic. The quadratic has two real roots and the septic has three. So there are five other real solutions. But all of them have some variables negative (and negative enough, even when evaluated to 100 digits, that I'm confident this is not the result of roundoff error).