numpy - Use Python SciPy to solve ODE -


now face problem when use scipy.integrate.ode.

i want use spectral method (fourier transform) solve pde including dispersive , convection term, such du/dt = * d^3 u / dx^3 + c * du/dx

then fourier transform pde convert set of odes in complex space (uk complex vector)

duk/dt = (a * coeff^3  + c * coeff) * uk  coeff = (2 * pi * * k) / l  

k wavenumber, (e.g.. k = 0, 1, 2, 3, -4, -3, -2, -1) i^2 = -1, l length of domain.

when use r = ode(uode).set_integrator('zvode', method='adams'), python warn like:

c zvode-- @ current t (=r1), mxstep (=i1) steps
taken on call before reaching tout
in above message, i1 = 500 in above message, r1 = 0.2191432098050d+00

i feel because time step chosen large, cannot decrease time step every step time consuming real problem. have other way resolve problem?

did consider solving odes symbolically? sympy can type

import sympy sy sy.init_printing()  # use ipython better results  sympy.abc import a, c, c, x, t  # variables  u = sy.function(b'u')(x,t) eq = sy.eq(u.diff(t), c*u) sl1 = sy.pde.pdsolve(eq, u) print("the solution of:") sy.pprint(eq) print("was determined be:") sy.pprint(sl1)  print("") print("substituting coefficient:") k,l = sy.symbols("k l", real=true) coeff = (2 * sy.pi * sy.i * k) / l cc = (a * coeff**3  + c * coeff) sl2 = sy.simplify(sl1.replace(c, cc)) sy.pprint(sl2) 

gives following output:

the solution of: ∂                       ──(u(x, t)) = c⋅u(x, t) ∂t                      determined be:                 c⋅t u(x, t) = f(x)⋅ℯ     substituting coefficient:                            ⎛   2    2      2⎞                  -2⋅ⅈ⋅π⋅k⋅t⋅⎝4⋅π ⋅a⋅k  - c⋅l ⎠                  ──────────────────────────────                                3                                             l                u(x, t) = f(x)⋅ℯ       

note f(x) depends on initial values of u(x,t=0), need provide. use sl2.rhs.evalf() substitute in numbers.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -