ode

ODE integration with discretized values

送分小仙女□ 提交于 2019-12-22 11:20:39
问题 I want to use scipy.integrate.ode solver. I can define the callable function f only as an array of discrete points (because it depends on results of integration from previous iterations). But from the documentation it seems that the integrator expects the callable to be a continuous function. I suppose some sort of interpolation needs to be done. Can the solver deal with this on its own, or do I need to write some interpolation routine? Is there some scipy documentation/tutorial that explains

Saving derivative values in ode45 in Matlab

╄→гoц情女王★ 提交于 2019-12-19 10:26:34
问题 I'm simulating equations of motion for a (somewhat odd) system with mass-springs and double pendulum, for which I have a mass matrix and function f(x), and call ode45 to solve M*x' = f(x,t); I have 5 state variables, q= [ QDot, phi, phiDot, r, rDot]'; (removed Q because nothing depends on it, QDot is current.) Now, to calculate some forces, I would like to also save the calculated values of rDotDot, which ode45 calculates for each integration step, however ode45 doesn't give this back. I've

Runge Kutta problems in JS

て烟熏妆下的殇ゞ 提交于 2019-12-19 10:26:20
问题 I'm attempting a Runge-Kutta implementation for a mass on a spring in Javascript and visualizing it with D3. The purpose is to compare it to Forward Euler and comment on the differences. My FE works fine and plots fine, but the Runge-Kutta is shooting off in a negative direction and never wrapping around. Here's a plunkr with the vis and the code, but I'll add the JS (only for the ODE solvers) too. // *** Functions for ODE Solvers *** // function FEx (x, v, h) { return x + h*v; } function FEv

Plotting ODEs, Isoclines using Python

旧街凉风 提交于 2019-12-19 04:10:36
问题 I am looking for a Python package that will allow me to plot something similar to the Java applet seen below: http://math.mit.edu/mathlets/mathlets/isoclines/ Does anyone know any ODE plotting packages for this? I can code something from scratch using Numpy, Matplotlib, but I wanted to ask around first. Thanks, 回答1: Sage will do this: x,y = var("x y") eq = y^3-3*y-x p = implicit_plot(eq==0,(x,-4,4),(y,-4,4)) p += plot_slope_field(eq, (x,-4,4),(y,-4,4), headlength=1e-8) p.show(aspect_ratio=1)

Pass args for solve_ivp (new SciPy ODE API)

亡梦爱人 提交于 2019-12-18 12:55:29
问题 For solving simple ODEs using SciPy, I used to use the odeint function, with form: scipy.integrate.odeint(func, y0, t, args=(), Dfun=None, col_deriv=0, full_output=0, ml=None, mu=None, rtol=None, atol=None, tcrit=None, h0=0.0, hmax=0.0, hmin=0.0, ixpr=0, mxstep=0, mxhnil=0, mxordn=12, mxords=5, printmessg=0)[source] where a simple function to be integrated could include additional arguments of the form: def dy_dt(t, y, arg1, arg2): # processing code here In SciPy 1.0, it seems the ode and

Double pendulum solution using GSL

淺唱寂寞╮ 提交于 2019-12-18 09:38:53
问题 I am learning to use GSL to solve ODE. I wanted to solve double pendulum problem using GSL ODE functions. I decided to use this equations: (source: http://www.physics.usyd.edu.au/~wheat/dpend_html/) My code: #include <iostream> #include <cmath> #include "gsl/gsl_errno.h" #include "gsl/gsl_matrix.h" #include "gsl/gsl_odeiv2.h" #include "constants.h" double L1; double L2; double M1; double M2; double T_START; double T_END; double S1_ANGLE; double S2_ANGLE; double V1_INIT; double V2_INIT; int

Change a constant in ODE calculations under particular conditions with a flag

匆匆过客 提交于 2019-12-18 09:31:39
问题 I have an ODE for calculating how acidicity changes. Everything is working just fine, only I would like to change a constant whenever acidicity reaches a critical point. It is supposed to be some kind of irreversible effect I wish to simulate. My constants are coming from a structure file (c) I load once in the ODE function. [Time,Results] = ode15s(@(x, c) f1(x, c),[0 c.length],x0,options); The main problem I have here is not telling Matlab to change the constant but remember if it happened

python code for multiple ode

泄露秘密 提交于 2019-12-18 09:14:58
问题 I want to write a fourth order Adams Bashforth to solve the system. And the following is what I have : the system is in the following link: system we have def AdamsBashforth4( f, x0, t ): """ Fourth-order Adams-Bashforth method:: u[n+1] = u[n] + dt/24.*(55.*f(u[n], t[n]) - 59*f(u[n-1], t[n-1]) + 37*f(u[n-2], t[n-2]) - 9*f(u[n-3], t[n-3])) for constant time step dt. RK2 is used as default solver for first steps. """ n = len( t ) x = numpy.array( [ x0 ] * n ) for i in xrange( n - 1 ): h = t[i+1

Replacing negative values in a model (system of ODEs) with zero

旧巷老猫 提交于 2019-12-18 04:59:10
问题 I'm currently working on solving a system of ordinary differential equations using deSolve , and was wondering if there's any way of preventing differential variable values from going below zero. I've seen a few other posts about setting negative values to zero in a vector, data frame, etc., but since this is a biological model (and it doesn't make sense for a T cell count to go negative), I need to stop it from happening to begin with so these values don't skew the results, not just replace

Optimize constants in differential equations in Python

假装没事ソ 提交于 2019-12-18 03:01:07
问题 Okay so how would i approach to writing a code to optimize the constants a and b in a differential equation, like dy/dt = a*y^2 + b, using curve_fit? I would be using odeint to solve the ODE and then curve_fit to optimize a and b. If you could please provide input on this situation i would greatly appreciate it! 回答1: You might be better served by looking at ODEs with Sympy. Scipy/Numpy are fundamentally numerical packages and aren't really set up to do algebraic/symbolic operations. 回答2: You