I want to solve system of equation described in the article Double Pendulum, similar like author, where in last step he claims that he "use a computer algebra program to solve equations (13) and (16)". To do this, I rewrite this equations in SymPy:
import sympy as s
m1, m2 = s.symbols('m1, m2')
g = s.symbols('g')
x1_d2, y1_d2, x2_d2, y2_d2 = s.symbols('x1_d2, y1_d2, x2_d2, y2_d2')
t1, t2, t1_d1, t1_d2, t2_d1, t2_d2 = s.symbols('t1, t2, t1_d1, t1_d2, t2_d1, t2_d2')
L1, L2 = s.symbols('L1, L2')
eq1 = x1_d2 + t1_d1**2 * L1 * s.sin(t1) - t1_d2 * L1 * s.cos(t1)
eq2 = y1_d2 - t1_d1**2 * L1 * s.cos(t1) - t1_d2 * L1 * s.sin(t1)
eq3 = x2_d2 - x1_d2 + t2_d1**2 * L2 * s.sin(t2) - t2_d2 * L2 * s.cos(t2)
eq4 = y2_d2 - y1_d2 - t2_d1**2 * L2 * s.cos(t2) - t2_d2 * L2 * s.sin(t2)
eq16 = s.sin(t2) * (m2 * y2_d2 + m2 * g) + s.cos(t2) * (m2 * x2_d2)
result1 = s.solve([eq1, eq2, eq3, eq4, eq16], \
[m1, m2, g, x1_d2, y1_d2, x2_d2, y2_d2, t1, t2, t1_d1, t1_d2, t2_d1, t2_d2, L1, L2], \
dict=True)
for r in result1:
print(r.keys())
eq13 = s.sin(t1) * (m1 * y1_d2 + m2 * y2_d2 + m2 * g + m1 * g) + s.cos(t1) * (m1 * x1_d2 + m2 * x2_d2)
result2 = s.solve([eq1, eq2, eq3, eq4, eq13], \
[m1, m2, g, x1_d2, y1_d2, x2_d2, y2_d2, t1, t2, t1_d1, t1_d2, t2_d1, t2_d2, L1, L2], \
dict=True)
for r in result2:
print(r.keys())
Looking on similar question like How can I solve system of linear equations in SymPy?
, I expected that SymPy simplify, and return equations in respect to each symbol, however for equation (16) I got the result only for: L1, g, t1, L2, t2, and not for y2_d2 t2_d2. And for equation (13) I got exception.
dict_keys([L1, g, t1, L2, t2])
dict_keys([L1, g, t1, L2, t2])
Traceback (most recent call last):
File "physics-simulations/formula.py", line 28, in <module>
dict=True)
File "/usr/lib/python3/dist-packages/sympy/solvers/solvers.py", line 1164, in solve
solution = _solve_system(f, symbols, **flags)
File "/usr/lib/python3/dist-packages/sympy/solvers/solvers.py", line 1911, in _solve_system
soln = _solve(eq2, s, **flags)
File "/usr/lib/python3/dist-packages/sympy/solvers/solvers.py", line 1752, in _solve
result = [r for r in result if
File "/usr/lib/python3/dist-packages/sympy/solvers/solvers.py", line 1753, in <listcomp>
checksol(f_num, {symbol: r}, **flags) is not False]
File "/usr/lib/python3/dist-packages/sympy/solvers/solvers.py", line 355, in checksol
return bool(abs(val.n(18).n(12, chop=True)) < 1e-9)
File "/usr/lib/python3/dist-packages/sympy/core/expr.py", line 336, in __lt__
raise TypeError("Invalid NaN comparison")
TypeError: Invalid NaN comparison
Edited:
How should my code look like, to solve/find two unknowns y1_d2, y2_d2 t1_d1, t2_d2 - equations (13, 16)?
This sort of manipulation is described here; using the focus routine described there you can feed your full equation set (cast as Eq instances) to focus and specify y1_d2 and y2_d2 as the variables on which you want to focus:
>>> F = (y1_d2, y2_d2)
>>> f = focus([Eq(i,0) for i in [eq1, eq2, eq3, eq4, eq16, eq13]], *F)
>>> [f[i].has(*F) for i in F]
[False, False]
>>> count_ops(f)
323
A compact result can be obtained with cse:
>>> r, e =cse([Eq(*i) for i in f.items()])
>>> for i in r:
... print('%s = %s' % i)
...
x0 = sin(t2)
x1 = cos(t2)
x2 = t2_d1**2
x3 = 1/(-t2_d2*x1 + x0*x2)
x4 = t2_d2*x0*x3
x5 = sin(t1)
x6 = cos(t1)
x7 = t1_d1**2
x8 = 1/(-t1_d2*x6 + x5*x7)
x9 = t1_d2*x5*x8
x10 = x1*x2*x3
x11 = x6*x7*x8
x12 = g/(x10 - x11 + x4 - x9)
x13 = x11*x12 + x12*x9
x14 = -x12 - x2_d2
>>> e
[Eq(y1_d2, x13), Eq(y2_d2, x10*x14 + x13 + x14*x4)]
I think the routines will only work with linear variables so if you want to solve for t1_d1 it will fail. But since t1_d1 only appears as a square you can replace it with y and focus on y. So here is a way to focus on t1_d1 and t2_d2:
>>> eqs = Tuple(*[Eq(i,0) for i in [eq1, eq2, eq3, eq4, eq16, eq13])
>>> S(focus(eqs.subs(t1_d1**2, y), y, t2_d2)).subs(y, t1_d1**2)
{t1_d1**2: (-L1*t1_d2*sin(t1) + y1_d2)/(L1*cos(t1)),
t2_d2: (-L2*t2_d1**2*cos(t2) - y1_d2 + y2_d2)/(L2*sin(t2))}
Thanks to smichr clue I was able to get desired result.
from sympy import symbols, sin, cos, solve, simplify, Eq
m1, m2 = symbols('m1, m2')
g = symbols('g')
t1, t2, t1_d1, t1_d2, t2_d1, t2_d2 = symbols('t1, t2, t1_d1, t1_d2, t2_d1, t2_d2')
L1, L2 = symbols('L1, L2')
x1_d2 = -t1_d1**2*L1*sin(t1) + t1_d2*L1*cos(t1)
y1_d2 = t1_d1**2*L1*cos(t1) + t1_d2*L1*sin(t1)
x2_d2 = x1_d2 - t2_d1**2*L2*sin(t2) + t2_d2*L2*cos(t2)
y2_d2 = y1_d2 + t2_d1**2*L2*cos(t2) + t2_d2*L2*sin(t2)
eq13 = Eq(sin(t1)*(m1*y1_d2 + m2*y2_d2 + m2*g + m1*g) + cos(t1)*(m1*x1_d2 + m2*x2_d2), 0)
eq16 = Eq(sin(t2)*(m2*y2_d2 + m2*g) + cos(t2)*(m2*x2_d2), 0)
solve([eq13, eq16], [t1_d1, t2_d2], dict=True)
Result:
[{t1_d1: -sqrt((L1*m2*t1_d2*sin(2*t1 - 2*t2) - (2*L1*m1*t1_d2 + L1*m2*t1_d2 + 2*L2*m2*t2_d1**2*sin(t1 - t2) + 2*g*m1*sin(t1) + g*m2*sin(t1) + g*m2*sin(t1 - 2*t2))*tan(2*t1 - 2*t2))/(L1*m2*sin(2*t1 - 2*t2)*tan(2*t1 - 2*t2))),
t2_d2: -(L1*m1*t1_d2 + L1*m2*t1_d2 + L2*m2*t2_d1**2*sin(t1 - t2) + g*m1*sin(t1) + g*m2*sin(t1))/(L2*m2*cos(t1 - t2))},
{t1_d1: sqrt((L1*m2*t1_d2*sin(2*t1 - 2*t2) - (2*L1*m1*t1_d2 + L1*m2*t1_d2 + 2*L2*m2*t2_d1**2*sin(t1 - t2) + 2*g*m1*sin(t1) + g*m2*sin(t1) + g*m2*sin(t1 - 2*t2))*tan(2*t1 - 2*t2))/(L1*m2*sin(2*t1 - 2*t2)*tan(2*t1 - 2*t2))),
t2_d2: -(L1*m1*t1_d2 + L1*m2*t1_d2 + L2*m2*t2_d1**2*sin(t1 - t2) + g*m1*sin(t1) + g*m2*sin(t1))/(L2*m2*cos(t1 - t2))}]
Related
Can somebody please point me in the right direction...
I need to find the parameters a,b,c,d of two functions:
Y1 = ( (a * X1 + b) * p0 + (c * X2 + d) * p1 ) / (a * X1 + b + c * X2 + d)
Y2 = ( (a * X2 + b) * p2 + (c * X2 + d) * p3 ) / (a * X1 + b + c * X2 + d)
X1, X2 (independent variables) and Y1, Y2 (dependent variables) are observations, i.e. one-dimensional arrays with thousands of entries each.
p0, p1, p2, p3 are known constants (scalars).
I successfully solved the problem with the first function only with a curve-fit (see below), but how do i solve the problem for Y1 and Y2 ?
Thank you.
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
X = [X1,X2]
def fitFunc(X, a,b,c,d):
X1, X2 = X
return ((a * X1 + b) * p0 + (c * X2 + d) * p1) / (a * X1 + b + c * X2 + d)
fitPar, fitCov = curve_fit(fitFunc, X, Y1)
print(fitPar)
One way would be to minimize both your functions together using scipy.optimize.minimze. In the example below, a function residual is passed a, b, c, and d as initial guesses. Using these guesses, Y1 and Y2 are evaluated, then the mean squared error is taken using the data and predicted values of respective functions. The error is returned as the mean error of the two functions. The optimized set of parameters is stored in res as res.x.
import numpy as np
from scipy.optimize import minimize
#p0 = ... known
#p1 = ... known
#p2 = ... known
#p3 = ... known
def Y1(X, a,b,c,d):
X1, X2 = X
return ((a * X1 + b) * p0 + (c * X2 + d) * p1) / (a * X1 + b + c * X2 + d)
def Y2(X, a,b,c,d):
X1, X2 = X
return ((a * X1 + b) * p2 + (c * X2 + d) * p3) / (a * X1 + b + c * X2 + d)
X1 = np.array([X1]) # your X1 array
X2 = np.array([X2]) # your X2 array
X = np.array([X1, X2])
y1_data = np.array([y1_data]) # your y1 data
y2_data = np.array([y2_data]) # your y2 data
def residual(x):
a = x[0]
b = x[1]
c = x[2]
d = x[3]
y1_pred = Y1(X,a,b,c,d)
y2_pred = Y2(X,a,b,c,d)
err1 = np.mean((y1_data - y1_pred)**2)
err2 = np.mean((y2_data - y2_pred)**2)
error = (err1 + err2) / 2
return error
x0 = [1, 1, 1, 1] # Initial guess for a, b, c, and d respectively
res = minimize(residual, x0, method="Nelder-Mead")
print(res.x)
I was using the 4th order Runge Kutta method to solve differential equations of the duffing oscillator with NumPy arrays, but I had received an Error.
RuntimeWarning: overflow encountered in double_scalars
Does anyone know the possible sources of error that may cause the overflow error and ways in which I would be able to try to resolve it?
t = np.linspace(0,1,steps)
# start at t=0
h = t[1] - t[0]
xn = np.zeros(steps)
xn[0] = 1
vn = np.zeros(steps)
vn[0] = 1
for n in range(1,steps):
k1 = vn[n-1]
l1 = g * np.cos(w * t[n-1]) - d * vn[n-1] - a * xn[n-1] - b * xn[n-1] **3
k2 = vn[n-1] + h*k1/2
l2 = g * np.cos(w * (t[n-1] + h/2)) - d * (vn[n-1] + h*k1/2) - a * (xn[n-1] + h*l1/2) - b * (xn[n-1] + h*l1/2)**3
k3 = vn[n-1] + h*k2/2
l3 = g * np.cos(w * (t[n-1] + h/2)) - d * (vn[n-1] + h*k2/2) - a * (xn[n-1] + h*l2/2) - b * (xn[n-1] + h*l2/2)**3
k4 = vn[n-1]*k3
l4 = g * np.cos(w * (t[n-1] + h)) - d * (vn[n-1] + h*k3) - a * (xn[n-1] + h*l3) - b * (xn[n-1] + h*l3)**3
vn[n] = vn[n-1] + h/6 * (k1 + 2* k2 + 2 * k3+ k4)
xn[n] = xn[n-1] + h/6 * (l1 + 2* l2 + 2* l3 + l4)
Here is my code for reference should anyone needs it. vn represents v_numerical
A link to Wikipedia for reference of the formula: https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods
I don't think it is very important to understand the formula, some possible solutions that I could try resolve the problem would be helpful.
The k are the updates for x, the l the updates for v, as v=dx/dt. You are changing the ODE into a different system of two half-coupled first-order equations.
Also note the typo or deletion error in k4.
So, I have this code below:
from sympy import Symbol, solve, nsolve
x1 = Symbol('x1')
x2 = Symbol('x2')
w1 = Symbol('w1')
w2 = Symbol('w2')
eq1 = w1 + w2
eq2 = (w1 * x1) + (w2 * x2)
eq3 = (w1 * x1**2) + (w2 * x2**2)
eq4 = (w1 * x1**3) + (w2 * x2**3)
print(nsolve((eq1, eq2, eq3, eq4), (x1, x2, w1, w2), (2, 0, 2/3, 0)))
For this question:
Which gives me this as a response:
x = findroot(f, x0, J=J, **kwargs)
File "C:\Users\Sabri\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\mpmath\calculus\optimization.py", line 969, in findroot
for x, error in iterations:
File "C:\Users\Sabri\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\mpmath\calculus\optimization.py", line 660, in __iter__
s = self.ctx.lu_solve(Jx, fxn)
File "C:\Users\Sabri\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\mpmath\matrices\linalg.py", line 226, in lu_solve
A, p = ctx.LU_decomp(A)
File "C:\Users\Sabri\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\mpmath\matrices\linalg.py", line 142, in LU_decomp
ctx.swap_row(A, j, p[j])
File "C:\Users\Sabri\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\mpmath\matrices\matrices.py", line 876, in swap_row
A[i,k], A[j,k] = A[j,k], A[i,k]
File "C:\Users\Sabri\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\mpmath\matrices\matrices.py", line 490, in __getitem__
if key[0] >= self.__rows or key[1] >= self.__cols:
TypeError: '>=' not supported between instances of 'NoneType' and 'int'
Following the documentation here:
https://docs.sympy.org/latest/modules/solvers/solvers.html
It's not very clear what is causing the issue, except one of the variables may be None. On Google, a lot of the issues with a similar error are explicitly shown, which is not the case here. Any suggestions?
Edit: I get this answer:
Using this code:
from scipy.optimize import fsolve
def func(p):
x1, x2, w1, w2 = p
return (w1 + w2, (w1 * x1) + (w2 * x2), (w1 * x1**2) + (w2 * x2**2), (w1 * x1**3) + (w2 * x2**3))
x1, x2, w1, w2 = fsolve(func, (2, 0, 2/3, 0))
print(x1, x2, w1, w2)
So the code should return a result, but I'm not sure why it doesn't work for Sympy. Thanks!
SymPy is able to solve sets of nonlinear equations, so if you prefer not to guess you can do:
>>> from sympy import Rational, nonlinsolve
>>> eq1 = w1 + w2 - 2
>>> eq2 = (w1 * x1) + (w2 * x2) - 0
>>> eq3 = (w1 * x1**2) + (w2 * x2**2) - Rational(2, 3) # 2/3 gives float 0.66..
>>> eq4 = (w1 * x1**3) + (w2 * x2**3) - 0
>>> nonlinsolve((eq1, eq2, eq3, eq4), (x1, x2, w1, w2))
FiniteSet((-sqrt(3)/3, sqrt(3)/3, 1, 1), (sqrt(3)/3, -sqrt(3)/3, 1, 1))
So that gives two solutions.
When use nsolve(), the RHS are all zeros. Non-zeros terms on RHS are moved (2, 0, 2/3, 0) to LHS.
The third argument to nsolve() is the initial guess close to the solution.
An educated guess is (x1,x2,w1,w2) = (-1,1,1,1) in the interval [-1,1] with equal weights.
I tried a few other guesses. some of them caused the same error.
Output:
w1 + w2 - 2
w1*x1 + w2*x2
w1*x1**2 + w2*x2**2 - 0.666666666666667
w1*x1**3 + w2*x2**3
Matrix([[-0.577350269189626], [0.577350269189626], [1.00000000000000], [1.00000000000000]])
The results agree with the n=2 case on table in Wikipedia.
Code:
from sympy import Symbol, solve, nsolve
x1 = Symbol('x1')
x2 = Symbol('x2')
w1 = Symbol('w1')
w2 = Symbol('w2')
eq1 = w1 + w2 - 2
eq2 = (w1 * x1) + (w2 * x2) - 0
eq3 = (w1 * x1**2) + (w2 * x2**2) - 2 / 3
eq4 = (w1 * x1**3) + (w2 * x2**3) - 0
print(eq1, eq2, eq3, eq4, sep='\n')
print(nsolve((eq1, eq2, eq3, eq4), (x1, x2, w1, w2), (-1, 1, 0.5, 0.5)))
I have wrote a code for Runge-Kutta 4th order, which works perfectly fine for a system of differential equations:
import numpy as np
import matplotlib.pyplot as plt
import numba
import time
start_time = time.clock()
#numba.jit()
def V(u,t):
x1,dx1, x2, dx2=u
ddx1=-w**2 * x1 -b * dx1
ddx2=-(w+0.5)**2 * x2 -(b+0.1) * dx2
return np.array([dx1,ddx1,dx2,ddx2])
#numba.jit()
def rk4(f, u0, t0, tf , n):
t = np.linspace(t0, tf, n+1)
u = np.array((n+1)*[u0])
h = t[1]-t[0]
for i in range(n):
k1 = h * f(u[i], t[i])
k2 = h * f(u[i] + 0.5 * k1, t[i] + 0.5*h)
k3 = h * f(u[i] + 0.5 * k2, t[i] + 0.5*h)
k4 = h * f(u[i] + k3, t[i] + h)
u[i+1] = u[i] + (k1 + 2*(k2 + k3) + k4) / 6
return u, t
u, t = rk4(V,np.array([0,0.2,0,0.3]) ,0,100, 20000)
print("Execution time:",time.clock() - start_time, "seconds")
x1,dx1,x2,dx2 = u.T
plt.plot(x1,x2)
plt.xlabel('X1')
plt.ylabel('X2')
plt.show()
The above code, returns the desired result:
And thanks to Numba JIT, this code works really fast. However, this method doesn't use adaptive step size and hence, it is not very suitable for a system of stiff differential equations. Runge Kutta Fehlberg method, solves this problem by using a straight forward algorithm. Based on the algorithm (https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta%E2%80%93Fehlberg_method) I wrote this code which works for only one differential equation :
import numpy as np
def rkf( f, a, b, x0, tol, hmax, hmin ):
a2 = 2.500000000000000e-01 # 1/4
a3 = 3.750000000000000e-01 # 3/8
a4 = 9.230769230769231e-01 # 12/13
a5 = 1.000000000000000e+00 # 1
a6 = 5.000000000000000e-01 # 1/2
b21 = 2.500000000000000e-01 # 1/4
b31 = 9.375000000000000e-02 # 3/32
b32 = 2.812500000000000e-01 # 9/32
b41 = 8.793809740555303e-01 # 1932/2197
b42 = -3.277196176604461e+00 # -7200/2197
b43 = 3.320892125625853e+00 # 7296/2197
b51 = 2.032407407407407e+00 # 439/216
b52 = -8.000000000000000e+00 # -8
b53 = 7.173489278752436e+00 # 3680/513
b54 = -2.058966861598441e-01 # -845/4104
b61 = -2.962962962962963e-01 # -8/27
b62 = 2.000000000000000e+00 # 2
b63 = -1.381676413255361e+00 # -3544/2565
b64 = 4.529727095516569e-01 # 1859/4104
b65 = -2.750000000000000e-01 # -11/40
r1 = 2.777777777777778e-03 # 1/360
r3 = -2.994152046783626e-02 # -128/4275
r4 = -2.919989367357789e-02 # -2197/75240
r5 = 2.000000000000000e-02 # 1/50
r6 = 3.636363636363636e-02 # 2/55
c1 = 1.157407407407407e-01 # 25/216
c3 = 5.489278752436647e-01 # 1408/2565
c4 = 5.353313840155945e-01 # 2197/4104
c5 = -2.000000000000000e-01 # -1/5
t = a
x = np.array(x0)
h = hmax
T = np.array( [t] )
X = np.array( [x] )
while t < b:
if t + h > b:
h = b - t
k1 = h * f( x, t )
k2 = h * f( x + b21 * k1, t + a2 * h )
k3 = h * f( x + b31 * k1 + b32 * k2, t + a3 * h )
k4 = h * f( x + b41 * k1 + b42 * k2 + b43 * k3, t + a4 * h )
k5 = h * f( x + b51 * k1 + b52 * k2 + b53 * k3 + b54 * k4, t + a5 * h )
k6 = h * f( x + b61 * k1 + b62 * k2 + b63 * k3 + b64 * k4 + b65 * k5, \
t + a6 * h )
r = abs( r1 * k1 + r3 * k3 + r4 * k4 + r5 * k5 + r6 * k6 ) / h
if len( np.shape( r ) ) > 0:
r = max( r )
if r <= tol:
t = t + h
x = x + c1 * k1 + c3 * k3 + c4 * k4 + c5 * k5
T = np.append( T, t )
X = np.append( X, [x], 0 )
h = h * min( max( 0.84 * ( tol / r )**0.25, 0.1 ), 4.0 )
if h > hmax:
h = hmax
elif h < hmin:
raise RuntimeError("Error: Could not converge to the required tolerance %e with minimum stepsize %e." % (tol,hmin))
break
return ( T, X )
but I'm struggling to convert it to a function like the first code, where I can input a system of differential equations. The most confusing part for me, is how can I vectorize everything in the second code without messing things up. In other words, I cannot reproduce the first result using the RKF algorithm. Can anyone point me in the right direction?
I'm not really sure where your problem lies. Setting the not given parameters to w=1; b=0.1 and calling, without changing anything
T, X = rkf( f=V, a=0, b=100, x0=[0,0.2,0,0.3], tol=1e-6, hmax=1e1, hmin=1e-16 )
gives the phase plot
The step sizes grow as the system slows down as
which is the expected behavior for an unfiltered step size controller.
I try to solve a system of 4 differential equations in sympy. I get a "NotImplementedError". Is there a workaround?
The set of ode's I am trying to solve is:
![ODE]: https://imgur.com/Xa5fwlt
I have tried substituting numerical values for the R12 to R45 symbols. I continue receiving the same error.
import sympy as sp
import numpy as np
import matplotlib.pyplot as plt
# Define symbols
m1, m2, m3, m4 = sp.symbols('m1 m2 m3 m4', real = True, positive=True)
c1, c2, c3, c4 = sp.symbols('c1 c2 c3 c4', real = True, positive=True)
R12, R25, R23, R34, R45 = sp.symbols('R12 R25 R23 R34 R45', real = True, positive=True) #0.2, 0.1, 2.7, 0.5, .6
T1, T2, T3, T4 = sp.symbols('T1 T2 T3 T4', cls=sp.Function)
qp, qel = sp.symbols('qp qel')
T5 = 25 # ambient temperature
# Define equations
eq1 = -sp.Eq(sp.Derivative(T1(t), t)) + - (T1(t)-T2(t)) / (R12 * m1 * c1)
eq2 = -sp.Eq(sp.Derivative(T2(t), t)) + 1 / (m2 * c2) * ((T1(t) - T2(t))/R12 + (T5-T2(t))/R25 - (T2(t)-T3(t))/R23)
eq3 = -sp.Eq(sp.Derivative(T3(t), t)) + 1 / (m3 * c3) * ((T2(t) - T3(t))/R23 + (T4(t)-T3(t))/R34 - qp)
eq4 = -sp.Eq(sp.Derivative(T4(t), t)) + 1 / (m4 * c4) * (qp - (T4(t) - T3(t))/R34 + (T4(t)-T5)/R45)
eq = (eq1, eq2, eq3, eq4)
funct = (T1(t), T2(t), T3(t), T4(t))
# Solve
sp.dsolve(eq, funct)
I expected to receive the symbolic solution for this set of differential equations.
The result is "NotImplementedError"
Your syntax for creating your equations is not correct. Eq needs to take two arguments, the left-hand side and the right-hand side.
eq1 = sp.Eq(sp.Derivative(T1(t), t), + - (T1(t)-T2(t)) / (R12 * m1 * c1))
eq2 = sp.Eq(sp.Derivative(T2(t), t), + 1 / (m2 * c2) * ((T1(t) - T2(t))/R12 + (T5-T2(t))/R25 - (T2(t)-T3(t))/R23))
eq3 = sp.Eq(sp.Derivative(T3(t), t), + 1 / (m3 * c3) * ((T2(t) - T3(t))/R23 + (T4(t)-T3(t))/R34 - qp))
eq4 = sp.Eq(sp.Derivative(T4(t), t), + 1 / (m4 * c4) * (qp - (T4(t) - T3(t))/R34 + (T4(t)-T5)/R45))
I did this and dsolve takes a while to compute the solution. It has to exponentiate a 4x4 symbolic matrix, which involves finding the symbolic eigenvalues, i.e., solving a quartic, which is very complicated in the general case.
SymPy could probably be improved here. Replacing symbolic parameters with numeric ones should make it go faster.