yes it is an Implicit Runge Kutta method !! I've already done this ! and actually now my solve methods is this :
d
I declare the equation inside the for loop (where else ?) because k1 , k2 are function of
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]