ode

Using scipy.integrate.complex_ode instead of scipy.integrate.ode

岁酱吖の 提交于 2019-11-28 04:34:39
问题 I am trying to use complex_ode method instead of ode method in scipy.integrate. The help page for complex_ode does not provide example, so I may have done something wrong. This code works properly with scipy.integrate.ode: 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

Using event function in matlab ode45 for multi-dimensional state vector

本秂侑毒 提交于 2019-11-28 02:19:23
I have a set of odes written in matrix form as $X' = AX$; I also have a desired value of the states $X_des$. $X$ is a five dimensional vector. I want to stop the integration after all the states reach their desired values (or atleast close to them by $1e{-3}$). How do I use event function in matlab to do this? (All the help I have seen are about 1 dimensional states) PS: I know for sure that all the states approach their desired values after long time. I just want to stop the integration once they are $1e{-3}$ within the desired values. First, I presume that you're aware that you can use the

Odd SciPy ODE Integration error

余生颓废 提交于 2019-11-27 22:22:30
I'm implementing a very simple Susceptible-Infected-Recovered model with a steady population for an idle side project - normally a pretty trivial task. But I'm running into solver errors using either PysCeS or SciPy, both of which use lsoda as their underlying solver. This only happens for particular values of a parameter, and I'm stumped as to why. The code I'm using is as follows: import numpy as np from pylab import * import scipy.integrate as spi #Parameter Values S0 = 99. I0 = 1. R0 = 0. PopIn= (S0, I0, R0) beta= 0.50 gamma=1/10. mu = 1/25550. t_end = 15000. t_start = 1. t_step = 1. t

Matlab ode45. How to change a parameter inside it while calling it?

南笙酒味 提交于 2019-11-27 15:39:27
I'm new with Matlab. I hope you can help me. I have to solve a system of ODEs using ODE45 function. Here is the function which describes my equitions. function dNdt = rateEquations(t, y) %populations of corresponding state Ng = y(1); Ns = y(2); Nt = y(3); %All constants used are dropped for the sake of easy reading. Note the parameter F. %rate equations dNs = s0 * Ng * F - Ns/ t_S1; dNt = Ns / t_ISC - Nt / t_T1; dNg = -dNt - dNs; dNdt = [dNg; dNs; dNt]; end Then, in my script .m-file i call the ode45 function in 'for loop'. During each iteration i have to change the parameter F and pass it to

Absolute error of ODE45 and Runge-Kutta methods compared with analytical solution

梦想与她 提交于 2019-11-27 08:29:25
I would appreciate if someone can help with the following issue. I have the following ODE: dr/dt = 4*exp(0.8*t) - 0.5*r ,r(0)=2, t[0,1] (1) I have solved (1) in two different ways. By means of the Runge-Kutta method (4th order) and by means of ode45 in Matlab. I have compared the both results with the analytic solution, which is given by: r(t) = 4/1.3 (exp(0.8*t) - exp(-0.5*t)) + 2*exp(-0.5*t) When I plot the absolute error of each method with respect to the exact solution, I get the following: For RK-method, my code is: h=1/50; x = 0:h:1; y = zeros(1,length(x)); y(1) = 2; F_xy = @(t,r) 4.*exp

Finding solution to Cauchy prob. in Matlab

穿精又带淫゛_ 提交于 2019-11-27 08:27:55
问题 I need some help with finding solution to Cauchy problem in Matlab. The problem: y''+10xy = 0, y(0) = 7, y '(0) = 3 Also I need to plot the graph. I wrote some code but, I'm not sure whether it's correct or not. Particularly in function section. Can somebody check it? If it's not correct, where I made a mistake? Here is separate function in other .m file: function dydx = funpr12(x,y) dydx = y(2)+10*x*y end Main: %% Cauchy problem clear all, clc xint = [0,5]; % interval y0 = [7;3]; % initial

Using adaptive step sizes with scipy.integrate.ode

£可爱£侵袭症+ 提交于 2019-11-27 05:37:10
问题 The (brief) documentation for scipy.integrate.ode says that two methods ( dopri5 and dop853 ) have stepsize control and dense output. Looking at the examples and the code itself, I can only see a very simple way to get output from an integrator. Namely, it looks like you just step the integrator forward by some fixed dt, get the function value(s) at that time, and repeat. My problem has pretty variable timescales, so I'd like to just get the values at whatever time steps it needs to evaluate

Solving an ODE when the function is given as discrete values -matlab-

元气小坏坏 提交于 2019-11-27 05:13:32
I have the following ODE: x_dot = 3*x.^0.5-2*x.^1.5 % (Equation 1) I am using ode45 to solve it. My solution is given as a vector of dim(k x 1) (usually k = 41, which is given by the tspan ). On the other hand, I have made a model that approximates the model from (1), but in order to compare how accurate this second model is, I want to solve it (solve the second ODE) by means of ode45 . My problem is that this second ode is given discrete: x_dot = f(x) % (Equation 2) f is discrete and not a continuous function like in (1). The values I have for f are: 0.5644 0.6473 0.7258 0.7999 0.8697 0.9353

Multiple scipy.integrate.ode instances

一个人想着一个人 提交于 2019-11-27 03:19:16
问题 I would like to use scipy.integrate.ode (or scipy.integrate.odeint) instances in multiple threads (one for each CPU core) in order to solve multiple IVPs at a time. However the documentation says: " This integrator is not re-entrant. You cannot have two ode instances using the “vode” integrator at the same time. " (Also odeint causes internal errors if instantiated multiple times although the documentation does not say so.) Any idea what can be done? 回答1: One option is to use multiprocessing

MATLAB: Is it possible to have two event values whilst using ode45?

这一生的挚爱 提交于 2019-11-26 23:18:51
I want two limitations to my ode45 calculation of a movement equation: position and time. I have already got the time event to work but I am not sure if and how I can add another event for limiting the position. EDIT: I also have many different particles coupled together in one ODE equation and need them to stop individually once they reach a 'roof' as they all travel at different speeds... would I be able to achieve this through events? I have an idea on how I would do this but its very complicated and would probably be very slow... I'm not sure if you can do exactly what you want, but it is