Why do I keep getting a negative solution in Maple?

215 Views Asked by At

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?

2

There are 2 best solutions below

4
On BEST ANSWER

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:

Sols1 := {solve({eq1,eq2,eq3, eq4, eq5, eq6, eq7, eq8, eq9})}:
Sols2 := remove(has,Sols1,I): # to get rid of non-real complex solutions
Sols := remove(hastype,Sols2,negative); # to get rid of solutions with negative numbers

$$\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).

0
On

This is not an answer but it is too long for a comment.

As Robert Israel answered, converting irrational numbers to rational numbers is a good practice when using a CAS.

I agree that you have a bunch of solutions but it could be much smaller if you take into account the fact that equations $5$ to $8$ are linear and that four variables may be immediatly eliminated, expressing them as functions of the other. For example, cascading the process, you have $$C1=\frac{7665 }{39658}C$$ $$C2=\frac{19584075 }{3073138078}C$$ $$CT1=\frac{2937611250}{538218547}C$$ $$CT2=\frac{18059659155344756250 }{1070078896020029089}C$$ Now, you can use the first equation and express $S$ as a function of $C,H,N$, then the second equation to express $T$ as a function of the same. So, you stay with equations $3,4,9$ which leads to a bunch of six possible solutions.

The only one I found which satisfies your criteria corresponds to $$C=0,H=0,N=13568634100$$ to which correspond $$C1=C2=CT1=CT2=T=0,S=N$$ I missed the other solution mentioned by Robert Israel.

As a side comment, when I need to solve systems of nonlinear equations, I personally prefer to use minimization of $$\Phi=\sum_{i=1}^N f_i^2$$ I would really appreciate to know what Maple would produce for your problem restricting it to non negative solutions.