Reputation: 1243
I have a system of 4 non-linear equations in 4 unknowns. In addition I have 1 inequality constraint that I need a function of the four unknowns to satisfy (and then I need the four unknowns to be non-negative). My problem has 12 or so parameters and I intend to eventually solve the problem for a range of parameters to see how the solution behaves. Not all parameters included in the code below are used in this particular setup (they are used in others). I understand that my system may not have a solution for all parameter values and that I will need to do some work to find the parameter space which works but before I do that I need to know how to solve a system of non-linear equations with inequality constraint. I am new to mathematica and I am including my code below. In the code I first give some parameter values, then I define some coefficients and then I write the 4 equations and 1 inequality inside the FindInstance function (which doesn't work). I have solved these 4 equations for a particular set of parameters with the FindRoot function but I got a solution that didn't satisfy the inequality. Thanks alot. The code in mathematica is below:
values = {{r, \[Delta], \[Sigma], Subscript[i, e], Subscript[i, u],
Subscript[\[Lambda], e ], Subscript[\[Lambda], u ], Subscript[H,
0], Subscript[C, f] , F, \[Tau], Subscript[C, Ren]}, {0.047, 0.05,
0.1632, 5, 0, 0.005, 0.02, 100, 17, 80, 0.3, 8}};
G = Grid[values,
Dividers -> {{None, None, None}, {{Blue}, {Blue}, None}}];
r = values[[2, 1]];
\[Delta] = values[[2, 2]];
\[Sigma] = values[[2, 3]];
Subscript[i, e] = values[[2, 4]];
Subscript[i, u] = values[[2, 5]];
Subscript[\[Lambda], e] = values[[2, 6]];
Subscript[\[Lambda], u] = values[[2, 7]];
Subscript[H, 0] = values[[2, 8]];
Subscript[C, f] = values[[2, 9]];
F = values[[2, 10]];
\[Tau] = values[[2, 11]];
Subscript[C, Ren] = values[[2, 12]];
Subscript[I, e] =
Subscript[i, e]/
r - (Subscript[i, e] - Subscript[i, u]) Subscript[\[Lambda],
e]/(r (r + Subscript[\[Lambda], e] + Subscript[\[Lambda], u]));
Subscript[I, u] =
Subscript[i, u]/
r + (Subscript[i, e] - Subscript[i, u]) Subscript[\[Lambda],
u]/(r (r + Subscript[\[Lambda], e] + Subscript[\[Lambda], u]));
Solve[k (k - 1) + 2 (r - \[Delta])/\[Sigma]^2 k - 2 r/\[Sigma]^2 == 0,
k];
{Subscript[k, 1 ], Subscript[k, 2 ]} = k /. % ;
Clear[k];
Subscript[k, 1]
Subscript[k, 2]
L1 = (H1S^(-Subscript[k, 1])* (F - (c1*F)/r + (
H1S^(Subscript[k, 2])*((F* H1D^(Subscript[k, 1])* (-c1 + r))/r +
H1S^(Subscript[k, 1])*(-(c0* F)/r + (c1*F)/
r + (H1D^(Subscript[k,
2])*(-F*H0D^(Subscript[k, 1])* (c0 - r) +
H0S^(Subscript[k, 1])* (c0*F - H0D *r +
r* Subscript[C, f])))/((H0D^(Subscript[k, 2])*
H0S^(Subscript[k, 1]) -
H0D^(Subscript[k, 1])* H0S^(Subscript[k, 2]))*
r) + (H1D^(Subscript[k,
1])*(F*H0D^(Subscript[k, 2])*(c0 - r) -
H0S^(Subscript[k, 2])* (c0*F - H0D* r +
r* Subscript[C, f])))/((H0D^(Subscript[k, 2])*
H0S^(Subscript[k, 1]) -
H0D^(Subscript[k, 1])* H0S^(Subscript[k, 2]))*r) +
Subscript[C, Ren])))/(
H1D^(Subscript[k, 2])* H1S^(Subscript[k, 1]) -
H1D^(Subscript[k, 1])* H1S^(Subscript[k, 2]))));
M1 = (((F* H1D^(Subscript[k, 1])* (-c1 + r))/r +
H1S^(Subscript[k, 1])*(-(c0* F)/r + (c1*F)/
r + (H1D^(Subscript[k,
2])*(-F*H0D^(Subscript[k, 1])* (c0 - r) +
H0S^(Subscript[k, 1])* (c0*F - H0D *r +
r* Subscript[C, f])))/((H0D^(Subscript[k, 2])*
H0S^(Subscript[k, 1]) -
H0D^(Subscript[k, 1])* H0S^(Subscript[k, 2]))*
r) + (H1D^(Subscript[k,
1])*(F*H0D^(Subscript[k, 2])*(c0 - r) -
H0S^(Subscript[k, 2])* (c0*F - H0D* r +
r* Subscript[C, f])))/((H0D^(Subscript[k, 2])*
H0S^(Subscript[k, 1]) -
H0D^(Subscript[k, 1])* H0S^(Subscript[k, 2]))*r) +
Subscript[C, Ren]))/(
H1D^(Subscript[k, 2])* H1S^(Subscript[k, 1]) -
H1D^(Subscript[k, 1])* H1S^(Subscript[k, 2])));
L0 = ((-F*H0D^(Subscript[k, 2])*(c0 - r) +
H0S^(Subscript[k, 2])*(c0*F - H0D*r +
r*Subscript[C, f]))/((H0D^(Subscript[k, 2])*
H0S^(Subscript[k, 1]) -
H0D^(Subscript[k, 1])* H0S^(Subscript[k, 2]))* r));
M0 = ((-F*H0D^(Subscript[k, 1])*(c0 - r) +
H0S^(Subscript[k, 1])*(c0*F - H0D*r +
r*Subscript[C, f]))/((H0D^(Subscript[k, 2])*
H0S^(Subscript[k, 1]) -
H0D^(Subscript[k, 1])* H0S^(Subscript[k, 2]))* r));
c0 = ((-F*H0D^(Subscript[k, 2])*r*Subscript[k, 1] +
H0S^(Subscript[k, 2])*
r*(-H0D + (H0D + Subscript[C, f])*Subscript[k, 1]))/(
F*(H0D^(Subscript[k, 2]) - H0S^(Subscript[k, 2]))*(-1 + \[Tau])*
Subscript[k, 1]));
c1 = (H1D^(Subscript[k, 1])*H1S^(Subscript[k, 1])*
r*(-1* F*H1S^(-Subscript[k, 1]) +
H1D^(-Subscript[k, 1]) *Subscript[C, Ren] + (
F*H1D^(-Subscript[k, 1])* (1 - \[Tau])*(-80*
H0D^(Subscript[k, 2])*Subscript[k, 1] +
H0S^(Subscript[k,
2])*(- H0D + (15 + H0D)* Subscript[k, 1])))/((-56*
H0D^(Subscript[k, 2]) + 56*H0S^(Subscript[k, 2]))*Subscript[
k, 1]) + (
F*H0S^(-Subscript[k,
1])*(r + ((1 - \[Tau])* (-80* H0D^(Subscript[k, 2])* r*
Subscript[k, 1] +
H0S^(Subscript[k, 2])*
r* (-H0D + (15 + H0D)*Subscript[k, 1])))/((-56*
H0D^(Subscript[k, 2]) + 56* H0S^(Subscript[k, 2]))*
Subscript[k, 1])))/r))/(
F *(H1S^(Subscript[k, 1]) - H1D^(Subscript[k, 1]))*(1 - \[Tau]));
A1 = (F*H1S^(-Subscript[k, 1])*(r + c1*(-1 + \[Tau]))*Subscript[k,
2])/(r *(Subscript[k, 1] - Subscript[k, 2]));
B1 = (F*H1S^(-Subscript[k, 2])*(r + c1*(-1 + \[Tau]))*Subscript[k,
1])/(r *(Subscript[k, 2] - Subscript[k, 1]));
FindInstance[
L1*Subscript[H, 0]^(Subscript[k, 1]) +
M1*Subscript[H, 0]^Subscript[k, 2] + c1*F/r == F &&
L0*H1D^(Subscript[k, 1]) + M0*H1D^Subscript[k, 2] + c0*F/r -
Subscript[C, Ren] ==
H1D - Subscript[C,
f] && (F*H0S^(-Subscript[k, 1])*(r + c0*(-1 + \[Tau]))* Subscript[
k, 2]) == (H0D^(-Subscript[k, 1])*(-H0D*
r + (H0D*r + c0*F *(-1 + \[Tau]) + r* Subscript[C, f])*
Subscript[k, 2])) && (F*
H1S^(-Subscript[k, 2])*(r + c1*(-1 + \[Tau]))*Subscript[k,
1]) == (H0S^(-Subscript[k, 2])*
H1D^(-Subscript[k, 2])*((-c0 + c1)*F*
H0S^(Subscript[k, 2])*(-1 + \[Tau]) +
F*H1D^(Subscript[k, 2])* (c0 + r - c0 *\[Tau]) +
H0S^(Subscript[k, 2])* r* Subscript[C, Ren])* Subscript[k,
1]) && A1*(Subscript[H, 0])^(Subscript[k, 1]) +
B1*(Subscript[H, 0])^(Subscript[k, 2]) + (H1S) - (1 - \[Tau])*c1*
F/r > 0 && H1S > 0 && H0S > 0 && H1D > 0 && H0D > 0, {H1S, H0S,
H1D, H0D}, Reals]
Clear[c0, c1, L0, L1, M0, M1, H1D, H0D, H1S, H0S]
Upvotes: 3
Views: 4178
Reputation: 3374
I don't believe you can use FindRoot
with constraints (inequalities, etc.). For non-linear constrained optimization you are going to want to investigate the following built in functions
I'm not sure which one you would want for this particular problem.
Here is an example of Maximize in action:
Maximize[{(2 x + y - z)/(5 x - 7 y + 3),
0 <= x + y + z <= 1 && 1 <= x - y + z <= 2 && x - y - z == 3}, {x,
y, z}]
which gives the following output:
{5/13, {x -> 2, y -> 0, z -> -1}}
More information on constrained optimization in Mathematica (including the non-linear variety) can be found at the following links:
I hope this helps.
Upvotes: 2