簡體   English   中英

如何求解非線性方程 將兩個值列表傳遞給 SciPy fsolve 參數

[英]how to solve non linear equation Pass two list of values to SciPy fsolve argument

我有以下 function:

具有相應變量的函數

    from optimize import fsolve
    import numpy as np
    T = np.array([137,145,150,152,159,160,184])
    Di =np.array([1,0,1,1,1,0,1])
    r = 5.0

    def lnL(P):
        mu, sigma = P
        return -r*np.log(sigma)-(1/2)*np.sum(Di*((T-mu)/sigma)**2)+np.sum(1-Di)

    sol = fsolve(lnL, (15.0,258.0))
    sol

我收到了這個錯誤:

fsolve: there is a mismatch between the input and output shape of the 'func' argument 'lnL'.Shape should be (2,) but it is (1,).

I have changed your function that you are using from optimize package, but the package fsolve and my function returns the same value after execution.

T = np.array([137, 145, 150, 152, 159, 160, 184])
Di = np.array([1, 0, 1, 1, 1, 0, 1])
r = 5.0
def lnL(mu, sigma):
    return np.log(sigma) - (1 / 2) * np.sum(Di * ((T - mu) / sigma) ** 2) + np.sum(1 - Di) * -r
sol = lnL(15.0, 258.0)
print(sol)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM