0
$\begingroup$

I am currently using the wrapper odeintw for scipy.integrate.odeint to solve my equations since they are complex-valued.

At the moment, I have 3 coupled first-order differential equations with 2 independent variables

\begin{align} \frac{\partial C}{\partial t} &= \frac{i}{a}(AB - cd) - \frac{C}{t_1}\\ \frac{\partial A}{\partial t} &= \frac{2ib^2}{a}cC - \frac{A}{t_2}\\ \frac{\partial B}{\partial t} &= ied + f \end{align}

Where the capital letters A, B, and C are my functions; the lower case letters a, b, c, t1, t2, and d are simply parameters; z and t are my independent variables. I've been able to solve the first two equations by simply making B equal to a constant (i.e. neglecting the 3rd equation) and inputting certain initial conditions/parameter values. The code is shown below and provides the real and imaginary part of the solutions separately (note: some of the variable names are different, but the equations are equivalent):

from odeintw import odeintw
import numpy as np
import matplotlib.pyplot as plt

def Wfunc(W, t, hbar, Pm, Em, Ep, T1, T2, d):
    N, Pp = W
    return [(1j/hbar)*(Pp*Ep - Em*Pm) - N/T1,
            (2j*(d**2)/hbar)*Em*N - Pp/T2]

W0 = np.array([1+2j, 3+4j])
t = np.linspace(0, 5, 1001)
hbar = 1.
Pm = 4 - 2j
Em = 2.5
Ep = 10.
T1 = 100.
T2 = 10
d = 0.1
W, infodict = odeintw(Wfunc, W0, t, args=(hbar, Pm, Em, Ep, T1, T2, d),
                  full_output=True)

plt.figure(1)
plt.clf()
color1 = (0.5, 0.4, 0.3)
color2 = (0.2, 0.2, 1.0)
plt.plot(t, W[:, 0].real, color=color1, label='N.real', linewidth=1.5)
plt.plot(t, W[:, 0].imag, '--', color=color1, label='N.imag', linewidth=2)
plt.plot(t, W[:, 1].real, color=color2, label='Pp.real', linewidth=1.5)
plt.plot(t, W[:, 1].imag, '--', color=color2, label='Pp.imag', linewidth=2)
plt.xlabel('t')
plt.grid(True)
plt.legend(loc='best')

plt.show()

This works as intended for the 2 equations with same independent variable, but now I want to introduce my other independent variable, z, and am running into a bit of difficulty. Are there any efficient ways to solve these 3 equations simultaneously? Extending the code for cases involving large intervals over the independent variables and more complex differential equations would be of interest.

$\endgroup$
3
  • $\begingroup$ Please provide your equations and a working code next time. $\endgroup$
    – nicoguaro
    May 18, 2016 at 17:50
  • $\begingroup$ Are you trying to move from an ODE to a PDE then? $\endgroup$
    – nicoguaro
    May 18, 2016 at 17:51
  • 1
    $\begingroup$ Where is $z$ in your differential equations? And I assume $d$ and $e$ are a constants as well? $\endgroup$
    – fibonatic
    May 19, 2016 at 8:05

1 Answer 1

3
$\begingroup$

You can integrate the third equation in $z$. Then you know $B$ up to a constant, right? Then $z$ is no longer an independent variable. Since it's then a 2-variable linear problem you can then just solve it analytically.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.