complex ODE systems in scipy

南楼画角 提交于 2019-12-03 20:12:23

I think we can at least point you in the right direction. The optical bloch equation is a problem which is well understood in the scientific community, although not by me :-), so there are already solutions on the internet to this particular problem.

http://massey.dur.ac.uk/jdp/code.html

However, to address your needs, you spoke of using complex_ode, which I suppose is fine, but I think just plain scipy.integrate.ode will work just fine as well according to their documentation:

 from scipy import eye
 from scipy.integrate import ode

 y0, t0 = [1.0j, 2.0], 0

 def f(t, y, arg1):
     return [1j*arg1*y[0] + y[1], -arg1*y[1]**2]
 def jac(t, y, arg1):
     return [[1j*arg1, 1], [0, -arg1*2*y[1]]]
 r = ode(f, jac).set_integrator('zvode', method='bdf', with_jacobian=True)
 r.set_initial_value(y0, t0).set_f_params(2.0).set_jac_params(2.0)
 t1 = 10
 dt = 1
 while r.successful() and r.t < t1:
     r.integrate(r.t+dt)
     print r.t, r.y

You also have the added benefit of an older more established and better documented function. I am surprised you have 8 and not 9 coupled ODE's, but I'm sure you understand this better than I. Yes, you are correct, your function should be of the form ydot = f(t,y), which you call def derv() but you're going to need to make sure your function takes at least two parameters like derv(t,y). If your y is in matrix, no problem! Just "reshape" it in the derv(t,y) function like so:

Y = numpy.reshape(y,(num_rows,num_cols));

As long as num_rows*num_cols = 8, your number of ODE's you should be fine. Then use the matrix in your computations. When you're all done, just be sure to return a vector and not a matrix like:

out = numpy.reshape(Y,(8,1));

The Jacobian is not required, but it will likely allow the computation to proceed much more quickly. If you do not know how to compute this you may want to consult wikipedia or a calculus text book. It's pretty simple, but can be time consuming.

As far as initial conditions, you should probably already know what those should be, whether it's complex or real valued. As long as you select values that are within reason, it shouldn't matter much.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!