user14650926
user14650926

Reputation: 11

sympy dsolve gives different result in google colab and jupyter notebook

My script gives different results if I run it on colab, jupyter notebook or directly. The colab result is wrong as the 3 equation are not coupled.

import sympy as sp
from IPython.display import *
sp.init_printing(use_latex=True)  
t,M_x0,My0,M_z0,w,k_2=sp.symbols('t,M_x0,My0,M_z0,omega,k_2',real=True)
M_x=sp.Function('M_x',real=True)(t)
M_y=sp.Function('M_y',real=True)(t)
M_z=sp.Function('M_z',real=True)(t)
e1=sp.Eq(sp.Derivative(M_x,t),w*M_y)           
e2=sp.Eq(sp.Derivative(M_y,t),-w*M_x)
e3=sp.Eq(sp.Derivative(M_z,t),0)
sys3 = [e1,e2,e3]
sol= sp.dsolve(sys3)
display('Systeme :',sys3)
display('Solution :',sol)

Upvotes: 1

Views: 346

Answers (1)

Oscar Benjamin
Oscar Benjamin

Reputation: 14480

The handling of systems of ODEs has been rewritten on sympy master and will be very different in sympy 1.7. This is what I get with current master (which will become 1.7):

In [7]: sys3                                                                                                                      
Out[7]: 
⎡d                     d                      d             ⎤
⎢──(Mₓ(t)) = ω⋅M_y(t), ──(M_y(t)) = -ω⋅Mₓ(t), ──(M_z(t)) = 0⎥
⎣dt                    dt                     dt            ⎦

In [8]: dsolve(sys3)                                                                                                              
Out[8]: [Mₓ(t) = C₁⋅sin(ω⋅t) + C₂⋅cos(ω⋅t), M_y(t) = C₁⋅cos(ω⋅t) - C₂⋅sin(ω⋅t), M_z(t) = C₃]

Upvotes: 1

Related Questions