Aug-13-2018, 04:44 PM
I'm trying to solve this system of non linear equations using scipy.optimize.fsolve , I took this from an example in one other post [here][1]
my system of equation is the follow :
I tried :
my system of equation is the follow :
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 (f1,f2) k1,k2 = fsolve(equations,(5,5))when I run the code I got :
TypeError: fsolve: there is a mismatch between the input and output shape of the 'func' argument 'equations'.Shape should be (2,) but it is (2, 1).I don't know why this mismatch and how to fix it ..
I tried :
for i in range(len(self.time)-1): ui = self.u[i] ti = self.time[i] def equations(variable): k1,k2 = variable f1 = -k1 + self.f(ti+ (0.5+np.sqrt(3)/6)* self.dt , ui+0.25*self.dt* k1+ (0.25+ np.sqrt(3)/6)*self.dt*k2) f2 = -k2 + self.f(ti+ (0.5-np.sqrt(3)/6)* self.dt , ui+(0.25-np.sqrt(3)/6)*self.dt *k1 + 0.25*self.dt* k2) return (f1,f2) k1,k2 = fsolve(equations,(1,1))how can I fix this mismatch ?