ode

integrate.ode sets t0 values outside of my data range

蹲街弑〆低调 提交于 2019-12-08 18:57:32
I would like to solve the ODE dy/dt = -2y + data(t), between t=0..3, for y(t=0)=1. I wrote the following code: import numpy as np from scipy.integrate import odeint from scipy.interpolate import interp1d t = np.linspace(0, 3, 4) data = [1, 2, 3, 4] linear_interpolation = interp1d(t, data) def func(y, t0): print 't0', t0 return -2*y + linear_interpolation(t0) soln = odeint(func, 1, t) When I run this code, I get several errors like this: ValueError: A value in x_new is above the interpolation range. odepack.error: Error occurred while calling the Python function named func My interpolation

How to draw the direction field of van der pol oscillator?

前提是你 提交于 2019-12-08 15:22:31
I am trying to get the direction field and phase portrait shown on this wiki page: Van der Pol oscillator in wikipedia My code: options = odeset('MaxStep',0.5); temp = inputdlg('Enter mu value'); mu = str2double(temp{1,1}); [t,y] = ode45(@(t,y) vdp1_1(t,y,mu),[0 10],[2; 0],options); plot(y(:,1),y(:,2)); hold on quiver(y(:,1), y(:,2), gradient(y(:,1)), gradient(y(:,2) )) hold off function dydt = vdp1_1(t,y,mu) dydt = zeros(2,1); dydt(1) = y(2); dydt(2) = [mu * (1-y(1)^2)*y(2)-y(1)]; end Current output: Desired Output: How to get the direction field on top of this as shown in the wiki page

Working out an equation

偶尔善良 提交于 2019-12-08 14:19:51
问题 I'm trying to solve a differential equation numerically, and am writing an equation that will give me an array of the solution to each time point. import numpy as np import matplotlib.pylab as plt pi=np.pi sin=np.sin cos=np.cos sqrt=np.sqrt alpha=pi/4 g=9.80665 y0=0.0 theta0=0.0 sina = sin(alpha)**2 second_term = g*sin(alpha)*cos(alpha) x0 = float(raw_input('What is the initial x in meters?')) x_vel0 = float(raw_input('What is the initial velocity in the x direction in m/s?')) y_vel0 = float

how to solve a system of Ordinary Differential Equations (ODE's) in Matlab

守給你的承諾、 提交于 2019-12-08 09:58:36
问题 I have to solve a system of ordinary differential equations of the form: dx/ds = 1/x * [y* (g + s/y) - a*x*f(x^2,y^2)] dy/ds = 1/x * [-y * (b + y) * f()] - y/s - c where x, and y are the variables I need to find out, and s is the independent variable; the rest are constants. I've tried to solve this with ode45 with no success so far: y = ode45(@yprime, s, [1 1]); function dyds = yprime(s,y) global g a v0 d dyds_1 = 1./y(1) .*(y(2) .* (g + s ./ y(2)) - a .* y(1) .* sqrt(y(1).^2 + (v0 + y(2)).

Valgrind output with address and question marks?

五迷三道 提交于 2019-12-08 03:18:56
问题 I have just receive an output from valgrind that I do not quite understand: ==20290== Invalid read of size 1 ==20290== at 0x8C1D678: ??? ==20290== by 0x5D74C47: ??? ==20290== Address 0xee818c7d is not stack'd, malloc'd or (recently) free'd ==20290== ==20290== ==20290== Process terminating with default action of signal 11 (SIGSEGV) ==20290== Access not within mapped region at address 0xEE818C7D ==20290== at 0x8C1D678: ??? ==20290== by 0x5D74C47: ??? ==20290== If you believe this happened as a

How to become aware of failure of ode45 without looking at the displayed warning?

别等时光非礼了梦想. 提交于 2019-12-07 23:40:00
问题 When the solution of ODE45 diverges (doesn't matter why and how), the following warning will be displayed, and the solver can not continue: Warning: Failure at t=8.190397e+01. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (2.273737e-13) at time t. I am running ode45 on a matrix (lots of inputs), so I want to find out automatically for which inputs the above condition(failure) happens. I mean, Is there any other sign of this condition

Internal working of scipy.integrate.ode

放肆的年华 提交于 2019-12-07 13:36:02
问题 I'm using scipy.integrate.ode and would like to know, what happens internally when I get the message UserWarning: zvode: Excess work done on this call. (Perhaps wrong MF.) 'Unexpected istate=%s' % istate)) This appears when I call ode.integrate(t1) for too big t1 , so I'm forced to use a for -loop and incrementally integrate my equation, what lowers the speed since the solver can not use adaptive step size very effectively. I already tried different methods and setting for the integrator. The

Update initial condition in ODE solver each time step

你。 提交于 2019-12-06 11:48:30
问题 I am wanting to solve a system of ODEs where for the first 30,000 seconds, I want one of my state variables to start from the same initial value. After those 30,000 seconds, I want to change the initial value of that state variable to something different and simulate the system for the rest of time. Here is my code: def ode_rhs(y, t): ydot[0] = -p[7]*y[0]*y[1] + p[8]*y[8] + p[9]*y[8] ydot[1] = -p[7]*y[0]*y[1] + p[8]*y[8] ydot[2] = -p[10]*y[2]*y[3] + p[11]*y[9] + p[12]*y[9] ydot[3] = -p[13]*y

How to become aware of failure of ode45 without looking at the displayed warning?

假如想象 提交于 2019-12-06 09:39:29
When the solution of ODE45 diverges (doesn't matter why and how), the following warning will be displayed, and the solver can not continue: Warning: Failure at t=8.190397e+01. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (2.273737e-13) at time t. I am running ode45 on a matrix (lots of inputs), so I want to find out automatically for which inputs the above condition(failure) happens. I mean, Is there any other sign of this condition returned by ode45 that can be written in an array automatically ? Something that can be used in a if

Python: Unable to solve a differential equation using odeint with signum function

二次信任 提交于 2019-12-06 08:51:19
I am trying to solve this problem: where U is here: s=c*e(t)+e_dot(t) and e(t)=theta(t)-thetad(t) and e_dot(t)=theta_dot(t)-thetad_dot(t) where thetad(theta desired)=sin(t)-- i.e signal to be tracked! and thetad_dot=cos(t),J=10,c=0.5,eta=0.5 I tried first with odeint- it gave error after t=0.4 that is theta(solution of above differential equation) fell flat to 0 and stayed thereafter. However when I tried to increase mxstep to 5000000 I could get somewhat correct graph till t=4.3s. I want to get a pure sinusoidal graph. That is I want theta(solution of the above differential equation) to track