如何用MATLAB或Python解决大型非线性方程组?

时间:2019-04-28 19:48:40

标签: python matlab nonlinear-optimization

问题描述

我正在尝试求解非线性方程组:

  • 我有60个方程式(其中3个方程式的变体替换了测量数据)和10个复数值未知数(细分为20个幅度/相位未知数)。
  • 幅值以dB为单位,应为-80到0之间的实数值,标记为s11db,s21db,s22db,s31db,s32db,s33db,s41db,s42db,s43db,s44db
  • 相位以弧度指定,应为介于0和2 * pi之间的实数值,标记为s11ph,s21ph,s22ph,s31ph,s32ph,s33ph,s41ph,s42ph,s43ph,s44ph
  • 4个附加约束方程式增强了被动性
    • |s11|^2+|s21|^2+|s31|^2+|s41|^2 <= 1
    • |s21|^2+|s22|^2+|s32|^2+|s42|^2 <= 1
    • |s31|^2+|s32|^2+|s33|^2+|s43|^2 <= 1
    • |s41|^2+|s42|^2+|s43|^2+|s44|^2 <= 1
  • 等式是:
    • ((s11 * (1 - (s43 * Γ2 * s43 * Γ1 + s33 * Γ1 + s44 * Γ2) (s33 * Γ1 * s44 * Γ2)) + s31 * Γ1 * s31 * (1-(s44 * Γ2)) + s31 * Γ1 * s43 * Γ2 * s41 + s41 * Γ2 * s41 * (1-( s33 * Γ1)) + s41 * Γ2 * s43 * Γ1 * s31) / (1 - (s43 * Γ2 * s43 * Γ1 + s33 * Γ1 + s44 * Γ2) + (s33 * Γ1 * s44 * Γ2)) = s11p
    • eq2 = (s32*Γ1*s31*(1-(s44*Γ2)+0)+s32*Γ1*s43*Γ2*s41+s42*Γ2 *s41*(1-(s33*Γ1))+s42*Γ2*s43*Γ1*s31+s21*(1 -(s43*Γ2*s43*Γ1+s33*Γ1+s44*Γ2)+(s33*Γ1*s44*Γ2))) / (1 -(s43*Γ2*s43*Γ1+s33*Γ1+s44*Γ2)+(s33*Γ1*s44*Γ2)) = s21p
    • eq3 = (s32*Γ1*s32*(1-(s44*Γ2)+0)+s32*Γ1*s43*Γ2*s42*(1-0+0)+s22*(1 -(s43*Γ2*s43*Γ1+s33*Γ1+s44*Γ2)+(s33*Γ1*s44*Γ2))+s42*Γ2* s42*(1-(s33*Γ1)+0)+s42*Γ2*s43*Γ1*s32*(1-0+0)) / (1 -(s43*Γ2*s43*Γ1+s33*Γ1+s44*Γ2)+(s33*Γ1*s44*Γ2)) = s22p

到目前为止我已经尝试过的

我试图用sympy的nsolve函数以及(稍作修改后)MATLAB的fsolve和lsqnonlin函数来解决这个问题,但是我对此并不太幸运。 nsolve出现了错误,但无法找到绑定结果的方法。另一方面,MATLAB几乎立即停止运行,并返回了与我为起点输入的任何猜测都非常接近的内容-虽然值在某种意义上是有界的,但它会尝试为我指定了实界的东西返回复数,所以我不确定这是怎么回事。

尝试使用Python

我在python中的尝试看起来像这样-我已经解决了这个问题,并包括了足够的数据集以能够运行脚本-混淆了读取和处理数据的位,并且这是事实将循环运行约1000次,对应的数据与其他频率下的测量结果略有不同。


    import sympy
    from sympy.core.power import Pow
    from sympy import I as j
    from sympy import Rel,Eq,Abs,nsolve
    import sys

    if __name__ == "__main__":

        # these are real valued.
        s11db,s21db,s22db,s31db,s32db,s33db,s41db,s42db,s43db,s44db=sympy.symbols('s11db s21db s22db s31db s32db s33db s41db s42db s43db s44db',real=True)
        s11ph,s21ph,s22ph,s31ph,s32ph,s33ph,s41ph,s42ph,s43ph,s44ph=sympy.symbols('s11ph s21ph s22ph s31ph s32ph s33ph s41ph s42ph s43ph s44ph',real=True)
        s11,s21,s22,s31,s32,s33,s41,s42,s43,s44=sympy.symbols('s11 s21 s22 s22 s31 s33 s41 s42 s43 s44')

        variablesdb=[s11db,s21db,s22db,s31db,s32db,s33db,s41db,s42db,s43db,s44db]
        variablesph=[s11ph,s21ph,s22ph,s31ph,s32ph,s33ph,s41ph,s42ph,s43ph,s44ph]
        variables = []
        variables.extend(variablesdb)
        variables.extend(variablesph)

        guessesdb=[-20,-20,-20,-20,-20,-20,-20,-20,-20,-20]
        guessesph = [0,0,0,0,0,0,0,0,0,0]
        guesses = []
        guesses.extend(guessesdb)
        guesses.extend(guessesph)

        s11 = Pow(10,(s11db/10)) * sympy.exp(j*s11ph)
        s21 = Pow(10,(s21db/10)) * sympy.exp(j*s21ph)
        s22 = Pow(10,(s22db/10)) * sympy.exp(j*s22ph)
        s31 = Pow(10,(s31db/10)) * sympy.exp(j*s31ph)
        s32 = Pow(10,(s32db/10)) * sympy.exp(j*s32ph)
        s33 = Pow(10,(s33db/10)) * sympy.exp(j*s33ph)
        s41 = Pow(10,(s41db/10)) * sympy.exp(j*s41ph)
        s42 = Pow(10,(s42db/10)) * sympy.exp(j*s42ph)
        s43 = Pow(10,(s43db/10)) * sympy.exp(j*s43ph)
        s44 = Pow(10,(s44db/10)) * sympy.exp(j*s44ph)
        mΓ1=[0.016748068572860958+0.02165573563670993j,\
            0.3524499197684044+1.01318272809286j, \
            0.9902384965572285-0.4090088119125726j,\
            0.9902384965572285-0.4090088119125726j,\
            0.8639480592070746-0.6312186830903206j,\
            0.8481899405540196-0.6521365553445038j,\
            0.8639480592070746-0.6312186830903206j,\
            0.8483474812536963-0.6520564750063542j,\
            0.8599389505285947-0.6367147924208255j,\
            0.844854651665744-0.6565142490941961j,\
            0.8599389505285947-0.6367147924208255j,\
            0.8596032944139899-0.6370905579072205j,\
            0.12178304066817838+0.23419002409258938j,\
            0.25810610017732+0.11233917791430391j,\
            -0.7881852138612478+0.2941231164148775j,\
            0.8537371705084078+0.46722896692551863j,\
            0.14050135652671147+0.3073232683089746j,\
            0.09456025715651947+0.3638487655929115j,\
            0.7994228601750994+0.36132988231302926j,\
            -0.5729577316366177+0.3829110562916974j]
        mΓ2=[0.01886638946281557+0.02291153736938316j,\
            0.41115632130362006+0.9904544135078267j,\
            -1.0602110266293787+0.12873002023570793j,\
            -1.0602110266293787+0.12873002023570793j,\
            0.12178304066817838+0.23419002409258938j,\
            0.25810610017732+0.11233917791430391j,\
            -0.7881852138612478+0.2941231164148775j,\
            0.8537371705084078+0.46722896692551863j,\
            0.14050135652671147+0.3073232683089746j,\
            0.09456025715651947+0.3638487655929115j,\
            0.7994228601750994+0.36132988231302926j,\
            -0.5729577316366177+0.3829110562916974j,\
            0.8639480592070746-0.6312186830903206j,\
            0.8481899405540196-0.6521365553445038j,\
            0.8639480592070746-0.6312186830903206j,\
            0.8483474812536963-0.6520564750063542j,\
            0.8599389505285947-0.6367147924208255j,\
            0.844854651665744-0.6565142490941961j,\
            0.8599389505285947-0.6367147924208255j,\
            0.8596032944139899-0.6370905579072205j]
        ms11p=[-0.06420852176004949+0.007606136138496574j,\
              -0.537896794882235+0.4041100722456898j,\
              0.1412012055714567+0.5635279161255173j,\
              0.1937727600367866+0.4292234886620929j,\
              0.1469515332766462+0.5314862612846253j,\
              0.1518709241016716+0.5310052159365275j,\
              0.1578520689668907+0.5331598663019053j,\
              0.1540581804228726+0.5392467784421259j,\
              0.1431331385368337+0.5325073157781589j,\
              0.1535928910517443+0.5342246999907136j,\
              0.1512448255547076+0.5392322097605335j,\
              0.1473241418663376+0.5318193110512432j,\
              -0.2363809027693515+0.1174058767406709j,\
              -0.163391416393593+0.08774117501580507j,\
              -0.4568108580888767-0.2143100180166485j,\
              0.193345944206058-0.04761628164099008j,\
              -0.237571999125396+0.1195031741294373j,\
              -0.2034191332391219+0.1681349627984851j,\
              0.03011118465025885-0.09412680418431373j,\
              -0.04464063283385059+0.3528230797332958j]
        ms21p=[-0.003180197204485371-0.002823666341755482j,\
              -0.1906367035405745+0.0686968862920421j,\
              -0.05526246736964503+0.02635489796438511j,\
              0.002518013584325512+0.06590835456839306j,\
              -0.03537661863079149+0.08706407624479129j,\
              -0.01805052294769753+0.08243849033759301j,\
              -0.07056927627440178+0.03869620150023408j,\
              0.02738173375006136+0.04029812368020189j,\
              -0.02971165660146774+0.08491907637374546j,\
              -0.02737424760484992+0.09187392180460466j,\
              0.001038602543646932+0.03696165082008047j,\
              0.01181224381379054+0.1271817903117702j,\
              -0.03214857971468995+0.1284805218320462j,\
              -0.01717410586879602+0.1297380448848506j,\
              -0.03433798336733016+0.06369364773628092j,\
              0.043654417400282+0.1396753864320528j,\
              -0.03468050284302436+0.1289630391584528j,\
              -0.03705274246077175+0.1366485542793229j,\
              0.02030699854620357+0.1217902270543576j,\
              -0.0236005339029794+0.1770862461678967j]
        ms22p=[-0.1624942212974896-0.004693967380702952j,\
              -0.284542316854743-0.7064738951728178j,\
              0.4536543123936424-0.4578177740567013j,\
              -0.1024338501849106-0.1979272945233151j,\
              -0.1097995580875526-0.198389196010508j,\
              -0.07902213390718082-0.08677717201029744j,\
              0.3602007967821697-0.4162898752449462j,\
              0.1822099768155973+0.3712680606767835j,\
              -0.09809454238916153-0.1552338582896147j,\
              -0.1688279742308047-0.115960920204985j,\
              0.2331637616249181+0.1528931729845114j,\
              -0.4800053258074745+0.09873053685139994j,\
              -0.7738872200476685-0.04023055998635539j,\
              -0.7721863083906342-0.02871292187380659j,\
              -0.7821436668003945-0.03478684929877463j,\
              -0.7693920578775125-0.04497757228074708j,\
              -0.7737959107116188-0.03930039783428967j,\
              -0.7721735572720234-0.03995110444341842j,\
              -0.7729703027226912-0.04204217380573128j,\
              -0.766856877704361-0.04045169338481738j]
        equations = [] # sympy equations
    #    equations.append(Rel(s11db,0,'<='))
    #    equations.append(Rel(s21db,0,'<='))
    #    equations.append(Rel(s22db,0,'<='))
    #    equations.append(Rel(s31db,0,'<='))
    #    equations.append(Rel(s32db,0,'<='))
    #    equations.append(Rel(s33db,0,'<='))
    #    equations.append(Rel(s41db,0,'<='))
    #    equations.append(Rel(s42db,0,'<='))
    #    equations.append(Rel(s43db,0,'<='))
    #    equations.append(Rel(s44db,0,'<='))
    #    equations.append(Rel(s11db,-80,'>='))
    #    equations.append(Rel(s21db,-80,'>='))
    #    equations.append(Rel(s22db,-80,'>='))
    #    equations.append(Rel(s31db,-80,'>='))
    #    equations.append(Rel(s32db,-80,'>='))
    #    equations.append(Rel(s33db,-80,'>='))
    #    equations.append(Rel(s41db,-80,'>='))
    #    equations.append(Rel(s42db,-80,'>='))
    #    equations.append(Rel(s43db,-80,'>='))
    #    equations.append(Rel(s44db,-80,'>='))
    #    equations.append(Rel(s11ph,0,'>='))
    #    equations.append(Rel(s21ph,0,'>='))
    #    equations.append(Rel(s22ph,0,'>='))
    #    equations.append(Rel(s31ph,0,'>='))
    #    equations.append(Rel(s32ph,0,'>='))
    #    equations.append(Rel(s33ph,0,'>='))
    #    equations.append(Rel(s41ph,0,'>='))
    #    equations.append(Rel(s42ph,0,'>='))
    #    equations.append(Rel(s43ph,0,'>='))
    #    equations.append(Rel(s44ph,0,'>='))
    #    equations.append(Rel(s11ph,2*sympy.pi,'<='))
    #    equations.append(Rel(s21ph,2*sympy.pi,'<='))
    #    equations.append(Rel(s22ph,2*sympy.pi,'<='))
    #    equations.append(Rel(s31ph,2*sympy.pi,'<='))
    #    equations.append(Rel(s32ph,2*sympy.pi,'<='))
    #    equations.append(Rel(s33ph,2*sympy.pi,'<='))
    #    equations.append(Rel(s41ph,2*sympy.pi,'<='))
    #    equations.append(Rel(s42ph,2*sympy.pi,'<='))
    #    equations.append(Rel(s43ph,2*sympy.pi,'<='))
    #    equations.append(Rel(s44ph,2*sympy.pi,'<='))

        for n in range(len(mΓ1)):
            Γ1 = mΓ1[n]
            Γ2 = mΓ2[n]
            s11p = ms11p[n]
            s21p = ms21p[n]
            s22p = ms22p[n]

            eq1 = Eq(((s11 * (1 - (s43 * Γ2 * s43 * Γ1 + s33 * Γ1 + s44 *  Γ2) \
                + (s33 * Γ1 * s44 * Γ2)) + s31 * Γ1 * s31 * (1-(s44 * Γ2)) \
                + s31 * Γ1 * s43 * Γ2 * s41 + s41 * Γ2 * s41 * (1-( s33 * Γ1))\
                + s41 * Γ2 * s43 * Γ1 * s31) / (1 - (s43 *  Γ2 * s43 * Γ1 \
                + s33 * Γ1 + s44 * Γ2) + (s33 * Γ1 * s44 * Γ2))),
                    s11p, evaluate=False)
            eq2 = Eq((s32*Γ1*s31*(1-(s44*Γ2)+0)+s32*Γ1*s43*Γ2*s41+s42*Γ2 \
                   *s41*(1-(s33*Γ1))+s42*Γ2*s43*Γ1*s31+s21*(1 \
                   -(s43*Γ2*s43*Γ1+s33*Γ1+s44*Γ2)+(s33*Γ1*s44*Γ2))) / (1 \
                   -(s43*Γ2*s43*Γ1+s33*Γ1+s44*Γ2)+(s33*Γ1*s44*Γ2)),
                        s21p, evaluate=False)
            eq3 = Eq((s32*Γ1*s32*(1-(s44*Γ2)+0)+s32*Γ1*s43*Γ2*s42*(1-0+0)+s22*(1 \
                   -(s43*Γ2*s43*Γ1+s33*Γ1+s44*Γ2)+(s33*Γ1*s44*Γ2))+s42*Γ2* \
                   s42*(1-(s33*Γ1)+0)+s42*Γ2*s43*Γ1*s32*(1-0+0)) / (1 \
                   -(s43*Γ2*s43*Γ1+s33*Γ1+s44*Γ2)+(s33*Γ1*s44*Γ2)),
                       s22p, evaluate=False)
            equations.append(eq1)
            equations.append(eq2)
            equations.append(eq3)

        print(nsolve(equations,variables,guesses))
        sys.exit(0)


    # would like to add the following constraints:
    # between one frequency and the next, dB value should be fairly stable
    # probably not more than a few dB of variation, phase value should be stable
    # too

    # dB values should be constrained between -80dB and 0dB
    # phase values should be constrained between 0 and 2π
    # low loss passivity conditions:
    # |s11|^2 + |s21|^2 + |s31|^2 + |s41|^2 <= 1 (should be close to 1 if low loss)
    # |s21|^2 + |s22|^2 + |s32|^2 + |s42|^2 <= 1 (should be close to 1 if low loss)
    # |s31|^2 + |s32|^2 + |s33|^2 + |s43|^2 <= 1 (should be close to 1 if low loss)
    # |s41|^2 + |s42|^2 + |s43|^2 + |s44|^2 <= 1 (should be close to 1 if low loss)
    # |sji|^2 <= 1   ;; equivalent to sjidb <= 0

在MATLAB中的尝试


    %% fbnd.m
    function F = fbnd(x)
        mr1=[0.016748068572860958+0.02165573563670993j
            0.3524499197684044+1.01318272809286j
            0.9902384965572285-0.4090088119125726j
            0.9902384965572285-0.4090088119125726j
            0.8639480592070746-0.6312186830903206j
            0.8481899405540196-0.6521365553445038j
            0.8639480592070746-0.6312186830903206j
            0.8483474812536963-0.6520564750063542j
            0.8599389505285947-0.6367147924208255j
            0.844854651665744-0.6565142490941961j
            0.8599389505285947-0.6367147924208255j
            0.8596032944139899-0.6370905579072205j
            0.12178304066817838+0.23419002409258938j
            0.25810610017732+0.11233917791430391j
            -0.7881852138612478+0.2941231164148775j
            0.8537371705084078+0.46722896692551863j
            0.14050135652671147+0.3073232683089746j
            0.09456025715651947+0.3638487655929115j
            0.7994228601750994+0.36132988231302926j
            -0.5729577316366177+0.3829110562916974j];
        mr2=[0.01886638946281557+0.02291153736938316j
            0.41115632130362006+0.9904544135078267j
            -1.0602110266293787+0.12873002023570793j
            -1.0602110266293787+0.12873002023570793j
            0.12178304066817838+0.23419002409258938j
            0.25810610017732+0.11233917791430391j
            -0.7881852138612478+0.2941231164148775j
            0.8537371705084078+0.46722896692551863j
            0.14050135652671147+0.3073232683089746j
            0.09456025715651947+0.3638487655929115j
            0.7994228601750994+0.36132988231302926j
            -0.5729577316366177+0.3829110562916974j
            0.8639480592070746-0.6312186830903206j
            0.8481899405540196-0.6521365553445038j
            0.8639480592070746-0.6312186830903206j
            0.8483474812536963-0.6520564750063542j
            0.8599389505285947-0.6367147924208255j
            0.844854651665744-0.6565142490941961j
            0.8599389505285947-0.6367147924208255j
            0.8596032944139899-0.6370905579072205j];
        ms11p=[-0.06420852176004949+0.007606136138496574j
              -0.537896794882235+0.4041100722456898j
              0.1412012055714567+0.5635279161255173j
              0.1937727600367866+0.4292234886620929j
              0.1469515332766462+0.5314862612846253j
              0.1518709241016716+0.5310052159365275j
              0.1578520689668907+0.5331598663019053j
              0.1540581804228726+0.5392467784421259j
              0.1431331385368337+0.5325073157781589j
              0.1535928910517443+0.5342246999907136j
              0.1512448255547076+0.5392322097605335j
              0.1473241418663376+0.5318193110512432j
              -0.2363809027693515+0.1174058767406709j
              -0.163391416393593+0.08774117501580507j
              -0.4568108580888767-0.2143100180166485j
              0.193345944206058-0.04761628164099008j
              -0.237571999125396+0.1195031741294373j
              -0.2034191332391219+0.1681349627984851j
              0.03011118465025885-0.09412680418431373j
              -0.04464063283385059+0.3528230797332958j];
        ms21p=[-0.003180197204485371-0.002823666341755482j
              -0.1906367035405745+0.0686968862920421j
              -0.05526246736964503+0.02635489796438511j
              0.002518013584325512+0.06590835456839306j
              -0.03537661863079149+0.08706407624479129j
              -0.01805052294769753+0.08243849033759301j
              -0.07056927627440178+0.03869620150023408j
              0.02738173375006136+0.04029812368020189j
              -0.02971165660146774+0.08491907637374546j
              -0.02737424760484992+0.09187392180460466j
              0.001038602543646932+0.03696165082008047j
              0.01181224381379054+0.1271817903117702j
              -0.03214857971468995+0.1284805218320462j
              -0.01717410586879602+0.1297380448848506j
              -0.03433798336733016+0.06369364773628092j
              0.043654417400282+0.1396753864320528j
              -0.03468050284302436+0.1289630391584528j
              -0.03705274246077175+0.1366485542793229j
              0.02030699854620357+0.1217902270543576j
              -0.0236005339029794+0.1770862461678967j];
        ms22p=[-0.1624942212974896-0.004693967380702952j
              -0.284542316854743-0.7064738951728178j
              0.4536543123936424-0.4578177740567013j
              -0.1024338501849106-0.1979272945233151j
              -0.1097995580875526-0.198389196010508j
              -0.07902213390718082-0.08677717201029744j
              0.3602007967821697-0.4162898752449462j
              0.1822099768155973+0.3712680606767835j
              -0.09809454238916153-0.1552338582896147j
              -0.1688279742308047-0.115960920204985j
              0.2331637616249181+0.1528931729845114j
              -0.4800053258074745+0.09873053685139994j
              -0.7738872200476685-0.04023055998635539j
              -0.7721863083906342-0.02871292187380659j
              -0.7821436668003945-0.03478684929877463j
              -0.7693920578775125-0.04497757228074708j
              -0.7737959107116188-0.03930039783428967j
              -0.7721735572720234-0.03995110444341842j
              -0.7729703027226912-0.04204217380573128j
              -0.766856877704361-0.04045169338481738j];
        F = zeros(60);



        for n=1:length(ms22p)
            r1 = mr1(n);
            r2 = mr2(n);
            s11p = ms11p(n);
            s21p = ms21p(n);
            s22p = ms22p(n);

            s11db = x(1);
            s21db = x(2);
            s22db = x(3);
            s31db = x(4);
            s32db = x(5);
            s33db = x(6);
            s41db = x(7);
            s42db = x(8);
            s43db = x(9);
            s44db = x(10);

            s11ph = x(11);
            s21ph = x(12);
            s22ph = x(13);
            s31ph = x(14);
            s32ph = x(15);
            s33ph = x(16);
            s41ph = x(17);
            s42ph = x(18);
            s43ph = x(19);
            s44ph = x(20);

            s = @(db,ph) 10.^(db/10) * exp(1j*ph);

            index = 3*(n-1)+1;
            F(index) = ((s(s11db,s11ph) * (1 - (s(s43db,s43ph) * r2 * s(s43db,s43ph) * r1 + s(s33db,s33ph) * r1 + s(s44db,s44ph) *  r2) ...
                + (s(s33db,s33ph) * r1 * s(s44db,s44ph) * r2)) + s(s31db,s31ph) * r1 * s(s31db,s31ph) * (1-(s(s44db,s44ph) * r2)) ...
                + s(s31db,s31ph) * r1 * s(s43db,s43ph) * r2 * s(s41db,s41ph) + s(s41db,s41ph) * r2 * s(s41db,s41ph) * (1-( s(s33db,s33ph) * r1)) ...
                + s(s41db,s41ph) * r2 * s(s43db,s43ph) * r1 * s(s31db,s31ph)) / (1 - (s(s43db,s43ph) *  r2 * s(s43db,s43ph) * r1 ...
                + s(s33db,s33ph) * r1 + s(s44db,s44ph) * r2) + (s(s33db,s33ph) * r1 * s(s44db,s44ph) * r2))) - s11p;
            index = 3*(n-1)+2;
            F(index) = ((s(s32db,s32ph)*r1*s(s31db,s31ph)*(1-(s(s44db,s44ph)*r2)+0)+s(s32db,s32ph)*r1*s(s43db,s43ph)*r2*s(s41db,s41ph)+s(s42db,s42ph)*r2 ...
                   *s(s41db,s41ph)*(1-(s(s33db,s33ph)*r1))+s(s42db,s42ph)*r2*s(s43db,s43ph)*r1*s(s31db,s31ph)+s(s21db,s21ph)*(1 ...
                   -(s(s43db,s43ph)*r2*s(s43db,s43ph)*r1+s(s33db,s33ph)*r1+s(s44db,s44ph)*r2)+(s(s33db,s33ph)*r1*s(s44db,s44ph)*r2))) / (1 ...
                   -(s(s43db,s43ph)*r2*s(s43db,s43ph)*r1+s(s33db,s33ph)*r1+s(s44db,s44ph)*r2)+(s(s33db,s33ph)*r1*s(s44db,s44ph)*r2))) - s21p;
            index = 3*(n-1)+3;
            F(index) = ((s(s32db,s32ph)*r1*s(s32db,s32ph)*(1-(s(s44db,s44ph)*r2)+0)+s(s32db,s32ph)*r1*s(s43db,s43ph)*r2*s(s42db,s42ph)*(1-0+0)+s(s22db,s22ph)*(1 ...
                   -(s(s43db,s43ph)*r2*s(s43db,s43ph)*r1+s(s33db,s33ph)*r1+s(s44db,s44ph)*r2)+(s(s33db,s33ph)*r1*s(s44db,s44ph)*r2))+s(s42db,s42ph)*r2* ...
                   s(s42db,s42ph)*(1-(s(s33db,s33ph)*r1)+0)+s(s42db,s42ph)*r2*s(s43db,s43ph)*r1*s(s32db,s32ph)*(1-0+0)) / (1 ...
                   -(s(s43db,s43ph)*r2*s(s43db,s43ph)*r1+s(s33db,s33ph)*r1+s(s44db,s44ph)*r2)+(s(s33db,s33ph)*r1*s(s44db,s44ph)*r2))) - s22p;
        end
    end

    %% solve.m
    lb = -80* [1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0];
    ub = 2*pi* [0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1];
    guesses = [-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,0,0,0,0,0,0,0,0,0,0];
    options = optimoptions(@lsqnonlin,'Algorithm','trust-region-reflective',...
        'MaxIterations',5000,...
        'Display','Iter-detailed'...
    );
    %$[x,res] = lsqnonlin(@fbnd,guesses,lb,ub,options);
    optionsf = optimoptions(@fsolve,'Algorithm','trust-region',...
        'Diagnostics','on')
    [x,res] = fsolve(@fbnd,guesses)

预期结果

我希望/希望在我指定的范围内得到一个解决方案(即合理的解决方案)。我不确定我使用的是正确的工具,还是不确定当前使用的工具是否正确。如果有人愿意向我指出正确的方向,我将不胜感激。

0 个答案:

没有答案