Python Forum
Solve a system of non-linear equations in Python (scipy.optimize.fsolve)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Solve a system of non-linear equations in Python (scipy.optimize.fsolve)
#3
yes it is an Implicit Runge Kutta method !! I've already done this ! and actually now my solve methods is this :

d
ef solve(self):
        '''
              perform Implicit RK4 scheme 
        '''
        self.time , self.u = self.dydt.createArray()
        print("Running Implicit RK 4th order") 
        
        for i in range(len(self.time)-1):

            def equations(variable):
                k1, k2 = variable
                f1 = -k1 + self.f(self.time[i]+ (0.5+np.sqrt(3)/6)* self.dt , self.u[i]+0.25*self.dt* k1+ (0.25+ np.sqrt(3)/6)*self.dt*k2) 
                f2 = -k2 + self.f(self.time[i]+ (0.5-np.sqrt(3)/6)* self.dt , self.u[i]+(0.25-np.sqrt(3)/6)*self.dt *k1 + 0.25*self.dt* k2)
                return np.array([f1,f2]).ravel() #.reshape(2,)  
                        
                
            k1 , k2 = fsolve(equations,(self.u[i],self.u[i]))
            
            self.u[i+1] = self.u[i] + self.dt/2* (k1 + k2)
 
        print('... Done!')
this works fine when I deal with a ODE single equations ... but doesn't works when I deal with system of ODE ... may you help me to find the right way to proceed ?

I declare the equation inside the for loop (where else ?) because k1 , k2 are function of
self.time[i], self.u[i] 
Reply


Messages In This Thread
RE: Solve a system of non-linear equations in Python (scipy.optimize.fsolve) - by drudox - Aug-14-2018, 07:08 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to run a linear model by group in Python? Betty775522 0 594 Oct-18-2023, 07:09 PM
Last Post: Betty775522
  How to optimize analog gauge reader? kadink 0 816 May-19-2023, 08:58 PM
Last Post: kadink
  Using scipy.optimize: curve_fit ju21878436312 0 1,006 Sep-24-2022, 01:15 PM
Last Post: ju21878436312
  SOLVED: scipy.optimize.least_squares problem Skytter13 2 2,982 Mar-06-2022, 10:17 AM
Last Post: Skytter13
  Help with Scipy optimize for numerical problem Jbjbjb1 0 1,584 Jun-22-2021, 05:03 AM
Last Post: Jbjbjb1
  how to solve the 'NO SUCH DIRECTORY OR FILE' in pandas, python MohammedSohail 10 15,816 May-08-2020, 07:45 AM
Last Post: nnk
  scipy.optimize.basinhopping generates unstable output bb19x11 0 1,702 Mar-09-2020, 04:07 PM
Last Post: bb19x11
  How to build linear regression by implementing Gradient Descent using only linear alg PythonSpeaker 1 2,247 Dec-01-2019, 05:35 PM
Last Post: Larz60+
  class for ODE, scipy how to switch from fsolve to newton or newton_krylov drudox 0 2,414 Aug-16-2018, 05:12 PM
Last Post: drudox
  Euler class for solve System of ODE drudox 0 2,982 Jul-08-2018, 09:31 PM
Last Post: drudox

Forum Jump:

User Panel Messages

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