Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Solving system of ODEs

I'm trying to solve a system of 4 ODEs using Sage. I'm able to get a solution, but it's not at all what I expect. Here are the 4 equations:

$$\frac{dw}{dt} = \frac{Q_x}{V} x(t) - \frac{Q_y}{V}\eta w(t) - \frac{Q_z}{V} \eta w(t)$$ $$\frac{dx}{dt} = \frac{Q_y}{V} \gamma y(t) + \frac{Q_z}{V} \zeta z(t) - \frac{Q_x}{V}x(t)$$ $$\frac{dy}{dt} = \frac{Q_y}{V} \eta w(t) - \frac{Q_y}{V} \gamma y(t) $$ $$\frac{dz}{dt} = \frac{Q_z}{V} \eta w(t) - \frac{Q_z}{V} \zeta z(t)$$

Here is how I've coded the problem in Sage.

eta, zeta, gamma = var('eta, zeta, gamma')
m_0, Qx, Qy, Qz, V = var('m_0, Q_x, Q_y, Q_z, V')
t = var('time')
w=function('w', t)
x=function('x', t)
y=function('y', t)
z=function('z', t)
dw = diff(w,t) - Qx/V*x + Qy/V*eta*w + Qz/V*eta*w == 0
dx = diff(x,t) - Qy/V*gamma*y - Qz/V*zeta*z + Qx/V*x == 0
dy = diff(y,t) - Qy/V*eta*w + Qy/V*gamma*y == 0
dz = diff(z,t) - Qz/V*eta*w + Qz/V*zeta*z == 0
eqs = [dw, dx, dy, dz]
vars = [w, x, y, z]
ics = [0, 0, m_0, 0, 0]
ans = desolve_system(eqs, vars, ics, ivar=t)
print ans

Where m_0 is an initial mass that exists in the x volume at time 0. All other volumes are empty at time 0.

I'm expecting relatively simple exponential equations as the solution, but what I get in return is some significantly more complex.

\begin{equation} w\left(\mathit{time}\right) = \frac{V \gamma m_{0} \zeta}{{\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta} + \mathcal{L}^{-1}\left(-\frac{V^{4} g_{2562}^{2} \gamma m_{0} \zeta + {\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} V^{2} \gamma^{2} m_{0} \zeta^{2} - {\left(Q_{x} Q_{z} \eta m_{0} \zeta^{2} + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta \gamma^{2} m_{0}\right)} V^{3} - {\left({\left(Q_{x} \eta \gamma m_{0} + Q_{x} \eta m_{0} \zeta\right)} V^{4} - {\left({\left(Q_{x} - Q_{z}\right)} \gamma^{2} m_{0} \zeta + Q_{z} \gamma m_{0} \zeta^{2}\right)} V^{3}\right)} g_{2562}}{{\left(V^{3} g_{2562}^{3} + {\left(Q_{x} V^{3} \eta + {\left({\left(Q_{x} - Q_{z}\right)} \gamma + Q_{z} \zeta + Q_{x}\right)} V^{2}\right)} g_{2562}^{2} + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \gamma \zeta + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta\right)} \zeta\right)} V + {\left({\left(Q_{x} Q_{z} \eta \zeta + Q_{x}^{2} \eta + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta \gamma\right)} V^{2} + {\left({\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \gamma + {\left(Q_{x} Q_{z} + {\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \gamma\right)} \zeta\right)} V\right)} g_{2562}\right)} {\left({\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta\right)}}, g_{2562}, \mathit{time}\right) \end{equation} \begin{equation} x\left(\mathit{time}\right) = \frac{V \eta \gamma m_{0} \zeta}{{\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta} + \mathcal{L}^{-1}\left(\frac{{\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} V \gamma^{2} m_{0} \zeta^{2} + {\left(Q_{x} Q_{z} \eta^{2} m_{0} \zeta^{2} + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta^{2} \gamma^{2} m_{0}\right)} V^{3} + {\left({\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \eta \gamma^{2} m_{0} \zeta + {\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \eta \gamma m_{0} \zeta^{2}\right)} V^{2} + {\left(V^{3} \gamma m_{0} \zeta + {\left(\eta \gamma m_{0} + \eta m_{0} \zeta\right)} V^{4}\right)} g_{2562}^{2} + {\left({\left(Q_{x} \eta^{2} \gamma m_{0} + Q_{x} \eta^{2} m_{0} \zeta\right)} V^{4} + {\left({\left(Q_{x} - Q_{z}\right)} \eta \gamma^{2} m_{0} + Q_{x} \eta \gamma m_{0} \zeta + Q_{z} \eta m_{0} \zeta^{2}\right)} V^{3} + {\left({\left(Q_{x} - Q_{z}\right)} \gamma^{2} m_{0} \zeta + Q_{z} \gamma m_{0} \zeta^{2}\right)} V^{2}\right)} g_{2562}}{{\left(V^{3} g_{2562}^{3} + {\left(Q_{x} V^{3} \eta + {\left({\left(Q_{x} - Q_{z}\right)} \gamma + Q_{z} \zeta + Q_{x}\right)} V^{2}\right)} g_{2562}^{2} + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \gamma \zeta + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta\right)} \zeta\right)} V + {\left({\left(Q_{x} Q_{z} \eta \zeta + Q_{x}^{2} \eta + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta \gamma\right)} V^{2} + {\left({\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \gamma + {\left(Q_{x} Q_{z} + {\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \gamma\right)} \zeta\right)} V\right)} g_{2562}\right)} {\left({\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta\right)}}, g_{2562}, \mathit{time}\right) \end{equation} \begin{equation} y\left(\mathit{time}\right) = \frac{V \eta m_{0} \zeta}{{\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta} + \mathcal{L}^{-1}\left(-\frac{V^{4} \eta g_{2562}^{2} m_{0} \zeta + {\left(Q_{x} Q_{z} \eta + {\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \eta \gamma\right)} V^{2} m_{0} \zeta^{2} + {\left(Q_{x} Q_{z} \eta^{2} m_{0} \zeta^{2} + Q_{x} Q_{z} \eta^{2} m_{0} \zeta - {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta^{2} \gamma m_{0}\right)} V^{3} + {\left(Q_{x} V^{4} \eta^{2} m_{0} \zeta + {\left(Q_{z} \eta m_{0} \zeta^{2} + {\left({\left(Q_{x} - Q_{z}\right)} \eta \gamma + Q_{x} \eta\right)} m_{0} \zeta\right)} V^{3}\right)} g_{2562}}{{\left(V^{3} g_{2562}^{3} + {\left(Q_{x} V^{3} \eta + {\left({\left(Q_{x} - Q_{z}\right)} \gamma + Q_{z} \zeta + Q_{x}\right)} V^{2}\right)} g_{2562}^{2} + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \gamma \zeta + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta\right)} \zeta\right)} V + {\left({\left(Q_{x} Q_{z} \eta \zeta + Q_{x}^{2} \eta + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta \gamma\right)} V^{2} + {\left({\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \gamma + {\left(Q_{x} Q_{z} + {\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \gamma\right)} \zeta\right)} V\right)} g_{2562}\right)} {\left({\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta\right)}}, g_{2562}, \mathit{time}\right) \end{equation} \begin{equation} z\left(\mathit{time}\right) = \frac{V \eta \gamma m_{0}}{{\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta} + \mathcal{L}^{-1}\left(-\frac{V^{4} \eta g_{2562}^{2} \gamma m_{0} - {\left(Q_{x} Q_{z} \eta^{2} m_{0} \zeta - {\left({\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta^{2} \gamma^{2} + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta^{2} \gamma\right)} m_{0}\right)} V^{3} + {\left({\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \eta \gamma^{2} m_{0} \zeta + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta \gamma^{2} m_{0}\right)} V^{2} + {\left(Q_{x} V^{4} \eta^{2} \gamma m_{0} + {\left(Q_{z} \eta \gamma m_{0} \zeta + {\left({\left(Q_{x} - Q_{z}\right)} \eta \gamma^{2} + Q_{x} \eta \gamma\right)} m_{0}\right)} V^{3}\right)} g_{2562}}{{\left(V^{3} g_{2562}^{3} + {\left(Q_{x} V^{3} \eta + {\left({\left(Q_{x} - Q_{z}\right)} \gamma + Q_{z} \zeta + Q_{x}\right)} V^{2}\right)} g_{2562}^{2} + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \gamma \zeta + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta\right)} \zeta\right)} V + {\left({\left(Q_{x} Q_{z} \eta \zeta + Q_{x}^{2} \eta + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta \gamma\right)} V^{2} + {\left({\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \gamma + {\left(Q_{x} Q_{z} + {\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \gamma\right)} \zeta\right)} V\right)} g_{2562}\right)} {\left({\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta\right)}}, g_{2562}, \mathit{time}\right) \end{equation}

Can anyone explain what I've done wrong?

click to hide/show revision 2
No.2 Revision

Solving system of ODEs

I'm trying to solve a system of 4 ODEs using Sage. I'm able to get a solution, but it's not at all what I expect. Here are the 4 equations:

$$\frac{dw}{dt} = \frac{Q_x}{V} x(t) - \frac{Q_y}{V}\eta w(t) - \frac{Q_z}{V} \eta w(t)$$ $$\frac{dx}{dt} = \frac{Q_y}{V} \gamma y(t) + \frac{Q_z}{V} \zeta z(t) - \frac{Q_x}{V}x(t)$$ $$\frac{dy}{dt} = \frac{Q_y}{V} \eta w(t) - \frac{Q_y}{V} \gamma y(t) $$ $$\frac{dz}{dt} = \frac{Q_z}{V} \eta w(t) - \frac{Q_z}{V} \zeta z(t)$$

Here is how I've coded the problem in Sage.

eta, zeta, gamma = var('eta, zeta, gamma')
m_0, Qx, Qy, Qz, V = var('m_0, Q_x, Q_y, Q_z, V')
t = var('time')
w=function('w', t)
x=function('x', t)
y=function('y', t)
z=function('z', t)
dw = diff(w,t) - Qx/V*x + Qy/V*eta*w + Qz/V*eta*w == 0
dx = diff(x,t) - Qy/V*gamma*y - Qz/V*zeta*z + Qx/V*x == 0
dy = diff(y,t) - Qy/V*eta*w + Qy/V*gamma*y == 0
dz = diff(z,t) - Qz/V*eta*w + Qz/V*zeta*z == 0
eqs = [dw, dx, dy, dz]
vars = [w, x, y, z]
ics = [0, 0, m_0, 0, 0]
ans = desolve_system(eqs, vars, ics, ivar=t)
print ans

Where m_0 is an initial mass that exists in the x volume at time 0. All other volumes are empty at time 0.

I'm expecting relatively simple exponential equations as the solution, but what I get in return is some significantly more complex.

\begin{equation} $$ w\left(\mathit{time}\right) = \frac{V \gamma m_{0} \zeta}{{\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta} + \mathcal{L}^{-1}\left(-\frac{V^{4} g_{2562}^{2} \gamma m_{0} \zeta + {\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} V^{2} \gamma^{2} m_{0} \zeta^{2} - {\left(Q_{x} Q_{z} \eta m_{0} \zeta^{2} + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta \gamma^{2} m_{0}\right)} V^{3} - {\left({\left(Q_{x} \eta \gamma m_{0} + Q_{x} \eta m_{0} \zeta\right)} V^{4} - {\left({\left(Q_{x} - Q_{z}\right)} \gamma^{2} m_{0} \zeta + Q_{z} \gamma m_{0} \zeta^{2}\right)} V^{3}\right)} g_{2562}}{{\left(V^{3} g_{2562}^{3} + {\left(Q_{x} V^{3} \eta + {\left({\left(Q_{x} - Q_{z}\right)} \gamma + Q_{z} \zeta + Q_{x}\right)} V^{2}\right)} g_{2562}^{2} + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \gamma \zeta + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta\right)} \zeta\right)} V + {\left({\left(Q_{x} Q_{z} \eta \zeta + Q_{x}^{2} \eta + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta \gamma\right)} V^{2} + {\left({\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \gamma + {\left(Q_{x} Q_{z} + {\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \gamma\right)} \zeta\right)} V\right)} g_{2562}\right)} {\left({\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta\right)}}, g_{2562}, \mathit{time}\right) \end{equation} \begin{equation} x\left(\mathit{time}\right) = \frac{V \eta \gamma m_{0} \zeta}{{\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta} + \mathcal{L}^{-1}\left(\frac{{\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} V \gamma^{2} m_{0} \zeta^{2} + {\left(Q_{x} Q_{z} \eta^{2} m_{0} \zeta^{2} + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta^{2} \gamma^{2} m_{0}\right)} V^{3} + {\left({\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \eta \gamma^{2} m_{0} \zeta + {\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \eta \gamma m_{0} \zeta^{2}\right)} V^{2} + {\left(V^{3} \gamma m_{0} \zeta + {\left(\eta \gamma m_{0} + \eta m_{0} \zeta\right)} V^{4}\right)} g_{2562}^{2} + {\left({\left(Q_{x} \eta^{2} \gamma m_{0} + Q_{x} \eta^{2} m_{0} \zeta\right)} V^{4} + {\left({\left(Q_{x} - Q_{z}\right)} \eta \gamma^{2} m_{0} + Q_{x} \eta \gamma m_{0} \zeta + Q_{z} \eta m_{0} \zeta^{2}\right)} V^{3} + {\left({\left(Q_{x} - Q_{z}\right)} \gamma^{2} m_{0} \zeta + Q_{z} \gamma m_{0} \zeta^{2}\right)} V^{2}\right)} g_{2562}}{{\left(V^{3} g_{2562}^{3} + {\left(Q_{x} V^{3} \eta + {\left({\left(Q_{x} - Q_{z}\right)} \gamma + Q_{z} \zeta + Q_{x}\right)} V^{2}\right)} g_{2562}^{2} + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \gamma \zeta + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta\right)} \zeta\right)} V + {\left({\left(Q_{x} Q_{z} \eta \zeta + Q_{x}^{2} \eta + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta \gamma\right)} V^{2} + {\left({\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \gamma + {\left(Q_{x} Q_{z} + {\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \gamma\right)} \zeta\right)} V\right)} g_{2562}\right)} {\left({\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta\right)}}, g_{2562}, \mathit{time}\right) \end{equation} \begin{equation} y\left(\mathit{time}\right) = \frac{V \eta m_{0} \zeta}{{\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta} + \mathcal{L}^{-1}\left(-\frac{V^{4} \eta g_{2562}^{2} m_{0} \zeta + {\left(Q_{x} Q_{z} \eta + {\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \eta \gamma\right)} V^{2} m_{0} \zeta^{2} + {\left(Q_{x} Q_{z} \eta^{2} m_{0} \zeta^{2} + Q_{x} Q_{z} \eta^{2} m_{0} \zeta - {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta^{2} \gamma m_{0}\right)} V^{3} + {\left(Q_{x} V^{4} \eta^{2} m_{0} \zeta + {\left(Q_{z} \eta m_{0} \zeta^{2} + {\left({\left(Q_{x} - Q_{z}\right)} \eta \gamma + Q_{x} \eta\right)} m_{0} \zeta\right)} V^{3}\right)} g_{2562}}{{\left(V^{3} g_{2562}^{3} + {\left(Q_{x} V^{3} \eta + {\left({\left(Q_{x} - Q_{z}\right)} \gamma + Q_{z} \zeta + Q_{x}\right)} V^{2}\right)} g_{2562}^{2} + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \gamma \zeta + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta\right)} \zeta\right)} V + {\left({\left(Q_{x} Q_{z} \eta \zeta + Q_{x}^{2} \eta + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta \gamma\right)} V^{2} + {\left({\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \gamma + {\left(Q_{x} Q_{z} + {\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \gamma\right)} \zeta\right)} V\right)} g_{2562}\right)} {\left({\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta\right)}}, g_{2562}, \mathit{time}\right) \end{equation} \begin{equation} z\left(\mathit{time}\right) = \frac{V \eta \gamma m_{0}}{{\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta} + \mathcal{L}^{-1}\left(-\frac{V^{4} \eta g_{2562}^{2} \gamma m_{0} - {\left(Q_{x} Q_{z} \eta^{2} m_{0} \zeta - {\left({\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta^{2} \gamma^{2} + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta^{2} \gamma\right)} m_{0}\right)} V^{3} + {\left({\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \eta \gamma^{2} m_{0} \zeta + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta \gamma^{2} m_{0}\right)} V^{2} + {\left(Q_{x} V^{4} \eta^{2} \gamma m_{0} + {\left(Q_{z} \eta \gamma m_{0} \zeta + {\left({\left(Q_{x} - Q_{z}\right)} \eta \gamma^{2} + Q_{x} \eta \gamma\right)} m_{0}\right)} V^{3}\right)} g_{2562}}{{\left(V^{3} g_{2562}^{3} + {\left(Q_{x} V^{3} \eta + {\left({\left(Q_{x} - Q_{z}\right)} \gamma + Q_{z} \zeta + Q_{x}\right)} V^{2}\right)} g_{2562}^{2} + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \gamma \zeta + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta\right)} \zeta\right)} V + {\left({\left(Q_{x} Q_{z} \eta \zeta + Q_{x}^{2} \eta + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta \gamma\right)} V^{2} + {\left({\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \gamma + {\left(Q_{x} Q_{z} + {\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \gamma\right)} \zeta\right)} V\right)} g_{2562}\right)} {\left({\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta\right)}}, g_{2562}, \mathit{time}\right) \end{equation}$$

Can anyone explain what I've done wrong?

click to hide/show revision 3
retagged

Solving system of ODEs

I'm trying to solve a system of 4 ODEs using Sage. I'm able to get a solution, but it's not at all what I expect. Here are the 4 equations:

$$\frac{dw}{dt} = \frac{Q_x}{V} x(t) - \frac{Q_y}{V}\eta w(t) - \frac{Q_z}{V} \eta w(t)$$ $$\frac{dx}{dt} = \frac{Q_y}{V} \gamma y(t) + \frac{Q_z}{V} \zeta z(t) - \frac{Q_x}{V}x(t)$$ $$\frac{dy}{dt} = \frac{Q_y}{V} \eta w(t) - \frac{Q_y}{V} \gamma y(t) $$ $$\frac{dz}{dt} = \frac{Q_z}{V} \eta w(t) - \frac{Q_z}{V} \zeta z(t)$$

Here is how I've coded the problem in Sage.

eta, zeta, gamma = var('eta, zeta, gamma')
m_0, Qx, Qy, Qz, V = var('m_0, Q_x, Q_y, Q_z, V')
t = var('time')
w=function('w', t)
x=function('x', t)
y=function('y', t)
z=function('z', t)
dw = diff(w,t) - Qx/V*x + Qy/V*eta*w + Qz/V*eta*w == 0
dx = diff(x,t) - Qy/V*gamma*y - Qz/V*zeta*z + Qx/V*x == 0
dy = diff(y,t) - Qy/V*eta*w + Qy/V*gamma*y == 0
dz = diff(z,t) - Qz/V*eta*w + Qz/V*zeta*z == 0
eqs = [dw, dx, dy, dz]
vars = [w, x, y, z]
ics = [0, 0, m_0, 0, 0]
ans = desolve_system(eqs, vars, ics, ivar=t)
print ans

Where m_0 is an initial mass that exists in the x volume at time 0. All other volumes are empty at time 0.

I'm expecting relatively simple exponential equations as the solution, but what I get in return is some significantly more complex.

$$ w\left(\mathit{time}\right) = \frac{V \gamma m_{0} \zeta}{{\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta} + \mathcal{L}^{-1}\left(-\frac{V^{4} g_{2562}^{2} \gamma m_{0} \zeta + {\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} V^{2} \gamma^{2} m_{0} \zeta^{2} - {\left(Q_{x} Q_{z} \eta m_{0} \zeta^{2} + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta \gamma^{2} m_{0}\right)} V^{3} - {\left({\left(Q_{x} \eta \gamma m_{0} + Q_{x} \eta m_{0} \zeta\right)} V^{4} - {\left({\left(Q_{x} - Q_{z}\right)} \gamma^{2} m_{0} \zeta + Q_{z} \gamma m_{0} \zeta^{2}\right)} V^{3}\right)} g_{2562}}{{\left(V^{3} g_{2562}^{3} + {\left(Q_{x} V^{3} \eta + {\left({\left(Q_{x} - Q_{z}\right)} \gamma + Q_{z} \zeta + Q_{x}\right)} V^{2}\right)} g_{2562}^{2} + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \gamma \zeta + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta\right)} \zeta\right)} V + {\left({\left(Q_{x} Q_{z} \eta \zeta + Q_{x}^{2} \eta + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta \gamma\right)} V^{2} + {\left({\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \gamma + {\left(Q_{x} Q_{z} + {\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \gamma\right)} \zeta\right)} V\right)} g_{2562}\right)} {\left({\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta\right)}}, g_{2562}, \mathit{time}\right) \end{equation} \begin{equation} x\left(\mathit{time}\right) = \frac{V \eta \gamma m_{0} \zeta}{{\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta} + \mathcal{L}^{-1}\left(\frac{{\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} V \gamma^{2} m_{0} \zeta^{2} + {\left(Q_{x} Q_{z} \eta^{2} m_{0} \zeta^{2} + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta^{2} \gamma^{2} m_{0}\right)} V^{3} + {\left({\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \eta \gamma^{2} m_{0} \zeta + {\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \eta \gamma m_{0} \zeta^{2}\right)} V^{2} + {\left(V^{3} \gamma m_{0} \zeta + {\left(\eta \gamma m_{0} + \eta m_{0} \zeta\right)} V^{4}\right)} g_{2562}^{2} + {\left({\left(Q_{x} \eta^{2} \gamma m_{0} + Q_{x} \eta^{2} m_{0} \zeta\right)} V^{4} + {\left({\left(Q_{x} - Q_{z}\right)} \eta \gamma^{2} m_{0} + Q_{x} \eta \gamma m_{0} \zeta + Q_{z} \eta m_{0} \zeta^{2}\right)} V^{3} + {\left({\left(Q_{x} - Q_{z}\right)} \gamma^{2} m_{0} \zeta + Q_{z} \gamma m_{0} \zeta^{2}\right)} V^{2}\right)} g_{2562}}{{\left(V^{3} g_{2562}^{3} + {\left(Q_{x} V^{3} \eta + {\left({\left(Q_{x} - Q_{z}\right)} \gamma + Q_{z} \zeta + Q_{x}\right)} V^{2}\right)} g_{2562}^{2} + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \gamma \zeta + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta\right)} \zeta\right)} V + {\left({\left(Q_{x} Q_{z} \eta \zeta + Q_{x}^{2} \eta + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta \gamma\right)} V^{2} + {\left({\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \gamma + {\left(Q_{x} Q_{z} + {\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \gamma\right)} \zeta\right)} V\right)} g_{2562}\right)} {\left({\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta\right)}}, g_{2562}, \mathit{time}\right) \end{equation} \begin{equation} y\left(\mathit{time}\right) = \frac{V \eta m_{0} \zeta}{{\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta} + \mathcal{L}^{-1}\left(-\frac{V^{4} \eta g_{2562}^{2} m_{0} \zeta + {\left(Q_{x} Q_{z} \eta + {\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \eta \gamma\right)} V^{2} m_{0} \zeta^{2} + {\left(Q_{x} Q_{z} \eta^{2} m_{0} \zeta^{2} + Q_{x} Q_{z} \eta^{2} m_{0} \zeta - {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta^{2} \gamma m_{0}\right)} V^{3} + {\left(Q_{x} V^{4} \eta^{2} m_{0} \zeta + {\left(Q_{z} \eta m_{0} \zeta^{2} + {\left({\left(Q_{x} - Q_{z}\right)} \eta \gamma + Q_{x} \eta\right)} m_{0} \zeta\right)} V^{3}\right)} g_{2562}}{{\left(V^{3} g_{2562}^{3} + {\left(Q_{x} V^{3} \eta + {\left({\left(Q_{x} - Q_{z}\right)} \gamma + Q_{z} \zeta + Q_{x}\right)} V^{2}\right)} g_{2562}^{2} + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \gamma \zeta + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta\right)} \zeta\right)} V + {\left({\left(Q_{x} Q_{z} \eta \zeta + Q_{x}^{2} \eta + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta \gamma\right)} V^{2} + {\left({\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \gamma + {\left(Q_{x} Q_{z} + {\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \gamma\right)} \zeta\right)} V\right)} g_{2562}\right)} {\left({\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta\right)}}, g_{2562}, \mathit{time}\right) \end{equation} \begin{equation} z\left(\mathit{time}\right) = \frac{V \eta \gamma m_{0}}{{\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta} + \mathcal{L}^{-1}\left(-\frac{V^{4} \eta g_{2562}^{2} \gamma m_{0} - {\left(Q_{x} Q_{z} \eta^{2} m_{0} \zeta - {\left({\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta^{2} \gamma^{2} + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta^{2} \gamma\right)} m_{0}\right)} V^{3} + {\left({\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \eta \gamma^{2} m_{0} \zeta + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta \gamma^{2} m_{0}\right)} V^{2} + {\left(Q_{x} V^{4} \eta^{2} \gamma m_{0} + {\left(Q_{z} \eta \gamma m_{0} \zeta + {\left({\left(Q_{x} - Q_{z}\right)} \eta \gamma^{2} + Q_{x} \eta \gamma\right)} m_{0}\right)} V^{3}\right)} g_{2562}}{{\left(V^{3} g_{2562}^{3} + {\left(Q_{x} V^{3} \eta + {\left({\left(Q_{x} - Q_{z}\right)} \gamma + Q_{z} \zeta + Q_{x}\right)} V^{2}\right)} g_{2562}^{2} + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \gamma \zeta + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left({\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta \gamma + {\left(Q_{x}^{2} Q_{z} - Q_{x} Q_{z}^{2}\right)} \eta\right)} \zeta\right)} V + {\left({\left(Q_{x} Q_{z} \eta \zeta + Q_{x}^{2} \eta + {\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \eta \gamma\right)} V^{2} + {\left({\left(Q_{x}^{2} - Q_{x} Q_{z}\right)} \gamma + {\left(Q_{x} Q_{z} + {\left(Q_{x} Q_{z} - Q_{z}^{2}\right)} \gamma\right)} \zeta\right)} V\right)} g_{2562}\right)} {\left({\left(\eta \gamma + {\left(\eta \gamma + \eta\right)} \zeta\right)} V + \gamma \zeta\right)}}, g_{2562}, \mathit{time}\right) $$

Can anyone explain what I've done wrong?