Mathematica:帮助求解具有不等式约束的非线性方程组

发布于 2024-11-05 18:18:07 字数 6229 浏览 1 评论 0原文

我有一个包含 4 个未知数的 4 个非线性方程组。另外,我有 1 个不等式约束,我需要四个未知数的函数来满足它(然后我需要四个未知数为非负)。我的问题有 12 个左右的参数,我打算最终解决一系列参数的问题,看看解决方案的表现如何。并非以下代码中包含的所有参数都在此特定设置中使用(它们在其他设置中使用)。我知道我的系统可能没有所有参数值的解,并且我需要做一些工作来找到有效的参数空间,但在此之前我需要知道如何求解非线性方程组不平等约束。我是mathematica 的新手,我在下面包含了我的代码。在代码中,我首先给出一些参数值,然后定义一些系数,然后在 FindInstance 函数中编写 4 个方程和 1 个不等式(这不起作用)。我已经使用 FindRoot 函数求解了一组特定参数的这 4 个方程,但得到的解不满足不等式。多谢。 mathematica中的代码如下:

    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]

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]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抚笙 2024-11-12 18:18:07

我不相信您可以使用带有约束(不等式等)的 FindRoot 。对于非线性约束优化,您需要研究以下内置函数

  • Maximize[...]
  • NMaximize[...]
  • FindMaximum[...]
  • Minimize[...]
  • NMinimize[...]
  • FindMinimum[ ...]

我不确定您想要哪一个来解决这个特定问题。

以下是最大化实际操作的示例:

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}]

它给出以下输出:

{5/13, {x -> 2, y -> 0, z -> -1}}

有关 Mathematica 中约束优化(包括非线性变量)的更多信息,请访问以下链接:

我希望这会有所帮助。

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

  • Maximize[...]
  • NMaximize[...]
  • FindMaximum[...]
  • Minimize[...]
  • NMinimize[...]
  • FindMinimum[...]

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文