ode

odepack.error: Extra arguments must be in a tuple

时光总嘲笑我的痴心妄想 提交于 2019-12-11 15:59:11
问题 I'm having some issues with my ode solver, I am trying to solve an SEIR problem and I keep getting the same errors dispite the code that i have based my code on being very similar. My code is: import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt # Total population, N. N1 = 55600 # Initial number of infected and recovered individuals, I0 and R0. I10, R10, E10 = 1, 0, 0 # Everyone else, S0, is susceptible to infection initially. S10 = N1 - I10 - R10 - E10 #

How to use one value of a matrix for each time step inside ode solver

空扰寡人 提交于 2019-12-11 14:58:50
问题 I have a vector x of length N and I want to use its values for solving the differential equation: dy/dt = x - 4*y . For each step I want the ode solver function to use one value of the vector and then use the next value of the matrix for the next step. I tried doing so by declaring the vector a global variable and use it like this inside the ode solver: global x tspan = 0:0.01:10; [t,filter_coef] = ode45(@ode_filter,tspan,0); and the solving function like this: function dx = ode_filter(t,fil)

Using scipy's solve_ivp to solve non linear pendulum motion

戏子无情 提交于 2019-12-11 12:27:33
问题 I am still trying to understand how solve_ivp works against odeint, but just as I was getting the hang of it something happened. I am trying to solve for the motion of a non linear pendulum. With odeint, everything works like a charm, on solve_ivp hoever something weird happens: import numpy as np from matplotlib import pyplot as plt from scipy.integrate import solve_ivp, odeint g = 9.81 l = 0.1 def f(t, r): omega = r[0] theta = r[1] return np.array([-g / l * np.sin(theta), omega]) time = np

Matlab ODE with varying parameters

一笑奈何 提交于 2019-12-11 12:04:35
问题 I am trying to do exactly what has been explained here: How solve a system of ordinary differntial equation with time-dependent parameters (part 2). Here is my code. I have no idea where I'm going wrong. function shi = shitry(t,y,b,bt) b = interp1(bt, b, t) a = 0.25; %loss of immunity rate % b = 0.0002; %infectivity rate q = 10; %population renewal m = 0.012; %death rate r = 0.14; %recovery rate shi(1) = q - m*y(1)-b*y(1)*y(2)+a*y(3); shi(2) = (b*y(1))- (m + r)*y(2); shi(3) = (r*y(2))-((m+a)

Using boost::numeric::odeint inside the class

允我心安 提交于 2019-12-11 09:33:15
问题 For a simulation, I'm using boost::numeric::odeint but I'm having a problem. I'm using the integrate function inside a method of one of my classes and I'm having the error of "no matching function for call to integrate". To be more clear, here is a compressed version of my code: #include "MotionGeneration.h" #include <boost/numeric/ublas/vector.hpp> #include <boost/numeric/ublas/matrix.hpp> typedef boost::array< double , 10 > state_type; MotionGeneration::MotionGeneration(some_data) { //My

Poincare Section of a system of second order odes

◇◆丶佛笑我妖孽 提交于 2019-12-11 09:26:06
问题 It is the first time I am trying to write a Poincare section code at Python. I borrowed the piece of code from here: https://github.com/williamgilpin/rk4/blob/master/rk4_demo.py and I have tried to run it for my system of second order coupled odes. The problem is that I do not see what I was expecting to. Actually, I need the Poincare section when x=0 and px>0 . I believe that my implementation is not the best out there. I would like to: Improve the way that the initial conditions are chosen.

MATLAB- ode solver: Unable to meet integration tolerances

左心房为你撑大大i 提交于 2019-12-11 09:06:09
问题 I have a problem with ode solver in MATLAB. I used all ode solver like ode23s, ode23, ode15s, ode45 and so on. And my code can not be calculated, because of error-warning: 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 would like to calculate it, please help me directly in my code. Thank you. First script: % floq.m global c_alpha c_beta c_gama om ms ks bs mii % Parameters c

How do I solve a second order differential equation in R?

允我心安 提交于 2019-12-11 08:10:13
问题 I am learning R to solve a second order differential equation(probably using deSolve package). Which I have written in python by writing it as two first order differential equations and is given below import numpy as np import matplotlib.pyplot as plt from scipy.integrate import odeint def fun(X, t): y , dy , z = X M = np.sqrt (1./3. * (1/2. * dy **2 + 1./2. * y **2)) dz = (M*z) # dz/dt ddy = -3.* M * dy - y # ddy/dt return [dy ,ddy ,dz] y0 = 1 dy0 = -0.1 z0 = 1. X0 = [y0, dy0, z0] M0 = np

Odd behavior of ODE in Scilab: equation dy/dx=A is not solved properly

て烟熏妆下的殇ゞ 提交于 2019-12-11 07:39:20
问题 I am still learning Scilab (5.5.2), so I am writing and running test codes to familiarize myself with the software. To test the numerical differential equation solver, I started easy from the equation dy/dx = A , which has as solution y = Ax+c (line equation). This is the code I wrote: // Function y = A*x+1 function ydot=fn(x, A) ydot=A endfunction A=2; //Initial conditions x0=0; y0=A*x0+1; //Numerical Solution x=[0:5]; y= ode(y0,x0,x,fn); //Analytical solution y2 = A*x+1; clf(); plot(x, y);

scipy.integrate.solve_ivp vectorized

时光总嘲笑我的痴心妄想 提交于 2019-12-11 05:24:32
问题 Trying to use the vectorized option for solve_ivp and strangely it throws an error that y0 must be 1 dimensional. MWE : from scipy.integrate import solve_ivp import numpy as np import math def f(t, y): theta = math.pi/4 ham = np.array([[1,0],[1,np.exp(-1j*theta*t)]]) return-1j * np.dot(ham,y) def main(): y0 = np.eye(2,dtype= np.complex128) t0 = 0 tmax = 10**(-6) sol=solve_ivp( lambda t,y :f(t,y),(t0,tmax),y0,method='RK45',vectorized=True) print(sol.y) if __name__ == '__main__': main() The