Python Forum
How to Solving non-linear equation using scipy.optimize fsolve with variable list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Solving non-linear equation using scipy.optimize fsolve with variable list
#1
Hi every one,
when i am trying solve this equation using fsolve with variables as list
[Image: 2ZOfu.png]
can any help me out.
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
i am getting this error
fsolve: there is a mismatch between the input and output shape of the 'func' argument 'lnL'.Shape should be (2,) but it is (1,).
Reply


Messages In This Thread
How to Solving non-linear equation using scipy.optimize fsolve with variable list - by djhak - Jun-09-2020, 02:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question written RK solving same equation with different graphs acbshinn 1 513 Feb-09-2024, 12:33 PM
Last Post: Gribouillis
  How can I multithread to optimize a groupby task: davisc4468 0 797 Jun-30-2023, 02:45 PM
Last Post: davisc4468
  Positive integral solutions for Linear Diophantine Equation august 4 1,369 Jan-13-2023, 09:48 PM
Last Post: Gribouillis
  Solving an equation by brute force within a range alexfrol86 3 2,997 Aug-09-2022, 09:44 AM
Last Post: Gribouillis
  Split string using variable found in a list japo85 2 1,419 Jul-11-2022, 08:52 AM
Last Post: japo85
  do you have an idea to optimize this code[recursion]]? netanelst 4 1,404 May-20-2022, 06:41 PM
Last Post: jefsummers
  Solving equation equal to zero: How to resolve the syntax error? alexfrol86 3 2,118 Feb-21-2022, 08:58 AM
Last Post: deanhystad
  SOlving LInear Equations in Python(Symoy, NUmpy) - Coefficient Problem quest 3 1,865 Jan-30-2022, 10:53 PM
Last Post: quest
  Optimization using scipy.optimize KaneBilliot 3 1,996 Nov-30-2021, 08:03 AM
Last Post: Gribouillis
  how can I solve fsolve function error? troddydeeneeeeeey 3 2,601 Oct-14-2021, 07:07 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020