odeint

Canot compile C++ which uses odeint from boost

三世轮回 提交于 2019-12-02 10:06:31
I'm on Ubuntu 12.04 & had some boost fies already in /usr/include. I did a sudo apt-get install libboost-all-dev and that installed a lot of files too. I don't want to remove this boost and install from source as several other packages depend on the version from the ubuntu repos. This is the sample code I want to run :- #include <iostream> #include <boost/numeric/odeint.hpp> using namespace std; using namespace boost::numeric::odeint; typedef vector< double > state_type; const double sigma = 10.0; const double R = 28.0; const double b = 8.0 / 3.0; void lorenz( state_type &x , state_type &dxdt

How to plot the Eigenvalues when solving matrix coupled differential equations in PYTHON?

喜夏-厌秋 提交于 2019-12-02 03:41:28
问题 Lets say we have three complex matrices and a system of coupled differential equations with these matrices. import numpy, scipy from numpy import (real,imag,matrix,linspace,array) from scipy.integrate import odeint import matplotlib.pyplot as plt def system(x,t): a1= x[0];a3= x[1];a5= x[2];a7= x[3]; a2= x[4];a4= x[5];a6= x[6];a8= x[7]; b1= x[8];b3= x[9];b5= x[10];b7= x[11]; b2= x[12];b4= x[13];b6= x[14];b8= x[15]; c1= x[16];c3= x[17];c5= x[18];c7= x[19]; c2= x[20];c4= x[21];c6= x[22];c8= x[23

How to plot the Eigenvalues when solving matrix coupled differential equations in PYTHON?

人走茶凉 提交于 2019-12-02 02:29:43
Lets say we have three complex matrices and a system of coupled differential equations with these matrices. import numpy, scipy from numpy import (real,imag,matrix,linspace,array) from scipy.integrate import odeint import matplotlib.pyplot as plt def system(x,t): a1= x[0];a3= x[1];a5= x[2];a7= x[3]; a2= x[4];a4= x[5];a6= x[6];a8= x[7]; b1= x[8];b3= x[9];b5= x[10];b7= x[11]; b2= x[12];b4= x[13];b6= x[14];b8= x[15]; c1= x[16];c3= x[17];c5= x[18];c7= x[19]; c2= x[20];c4= x[21];c6= x[22];c8= x[23]; A= matrix([ [a1+1j*a2,a3+1j*a4],[a5+1j*a6,a7+1j*a8] ]) B= matrix([ [b1+1j*b2,b3+1j*b4],[b5+1j*b6,b7

How to make two sliders in matplotlib

眉间皱痕 提交于 2019-12-02 01:40:19
I would like to make two sliders in matplotlib to manually change N and P values in my predator-prey model: import numpy as np import matplotlib.pyplot as plt from scipy.integrate import odeint def lotka(x,t,params): N, P = x alpha, beta, gamma, delta = params derivs = [alpha*N - beta*N*P, gamma*N*P - delta*P] return derivs N=2 P=1 alpha=3 beta=0.5 gamma=0.4 delta=3 params = [alpha, beta, gamma, delta] x0=[N,P] maxt = 20 tstep = 0.01 t=np.arange(0,maxt,tstep) equation=odeint(lotka, x0, t, args=(params,)) plt.plot(t,equation) plt.xlabel("Time") plt.ylabel("Population size") plt.legend(["Prey",

extract values from function used by odeint scipy python

随声附和 提交于 2019-12-01 09:04:14
I have the following script to calculate dRho using odeint. P_r = 10e5 rho_r = 900 L = 750 H = 10 W = 150 A = H * W V = A * L fi = 0.17 k = 1.2e-13 c = 12.8e-9 mu = 2e-3 N = 50 dV = V/N dx = L/N P_in = P_r rho_in = rho_r P_w = 1e5 rho_w = rho_r* np.exp(c*(P_w-P_r)) # init initial case P = np.empty(N+1)*10e5 Q = np.ones(N+1) out = np.empty(N+1) P[0] = P_w Q[0] = 0 out[0] = 0 def dRho(rho_y, t, N): P[1:N] = P_r + (1/c) * np.log(rho_y[1:N]/rho_r) P[N] = P_r + (1/c) * np.log(rho_y[N]/rho_r) Q[1:N] = (-A*k/mu)*((P[1-1:N-1] - P[1:N])/dx) Q[N] = (-A*k/mu)*((P[N]-P_r)/dx) out[1:N] = ((Q[1+1:N+1]*rho_y

Bound an odeint variable

一笑奈何 提交于 2019-12-01 08:01:12
I'm using odeint to simulate a system wherein there are several variables which should not go less than zero. Is there an appropriate way to bound a variable in odeint to a particular range? There is no such possibility in odeint. And I guess there are no algorithms which could do that. You must somehow encode the bound in your ODE. If you only want to find a bound during the evolution of your system use a loop like while( t < tmax ) { stepper.do_step( ode , x , t , dt ); t += dt; if( check_bound( x , t ) ) break; } Two side nodes, maybe this is the case for your problem: There are special

Bound an odeint variable

限于喜欢 提交于 2019-12-01 07:10:32
问题 I'm using odeint to simulate a system wherein there are several variables which should not go less than zero. Is there an appropriate way to bound a variable in odeint to a particular range? 回答1: There is no such possibility in odeint. And I guess there are no algorithms which could do that. You must somehow encode the bound in your ODE. If you only want to find a bound during the evolution of your system use a loop like while( t < tmax ) { stepper.do_step( ode , x , t , dt ); t += dt; if(

extract values from function used by odeint scipy python

本小妞迷上赌 提交于 2019-12-01 06:11:05
问题 I have the following script to calculate dRho using odeint. P_r = 10e5 rho_r = 900 L = 750 H = 10 W = 150 A = H * W V = A * L fi = 0.17 k = 1.2e-13 c = 12.8e-9 mu = 2e-3 N = 50 dV = V/N dx = L/N P_in = P_r rho_in = rho_r P_w = 1e5 rho_w = rho_r* np.exp(c*(P_w-P_r)) # init initial case P = np.empty(N+1)*10e5 Q = np.ones(N+1) out = np.empty(N+1) P[0] = P_w Q[0] = 0 out[0] = 0 def dRho(rho_y, t, N): P[1:N] = P_r + (1/c) * np.log(rho_y[1:N]/rho_r) P[N] = P_r + (1/c) * np.log(rho_y[N]/rho_r) Q[1:N

NumPy odeint output extra variables

三世轮回 提交于 2019-12-01 01:06:47
What is the easiest way to save intermediate variables during simulation with odeint in Numpy? For example: def dy(y,t) x = np.rand(3,1) return y + x.sum() sim = odeint(dy,0,np.arange(0,1,0.1)) What would be the easiest way to save the data stored in x during simulation? Ideally at the points specified in the t argument passed to odeint . A handy way to hack odeint, with some caveats, is to wrap your call to odeint in method in a class, with dy as another method, and pass self as an argument to your dy function. For example, class WrapODE(object): def __init__(self): self.y_0 = 0. self.L_x = [

Scipy odeint giving lsoda warning

邮差的信 提交于 2019-11-30 23:19:05
I am totally new to coding and I want to solve these 5 differential equations numerically. I took a python template and applied it to my case. Here's the simplified version of what I wrote: import numpy as np from math import * from matplotlib import rc, font_manager import matplotlib.pyplot as plt from scipy.integrate import odeint #Constants and parameters alpha=1/137. k=1.e-9 T=40. V= 6.e-6 r = 6.9673e12 u = 1.51856e7 #defining dy/dt's def f(y, t): A = y[0] B = y[1] C = y[2] D = y[3] E = y[4] # the model equations f0 = 1.519e21*(-2*k/T*(k - (alpha/pi)*(B+V))*A) f1 = (3*B**2 + 3*C**2 + 6*B*C