ode

Detecting steady-state by calculating ODE values in ODE function in Matlab

只愿长相守 提交于 2019-12-12 18:24:42
问题 I have a system of ODE equations which I want to solve, but there is a tricky part that when the system reaches steady-state, I would like to change the value of one (or more) parameters. For example, consider the following: function dydt = diff(t,x,params) F = params(1); G = params(2); dydt = zeros(2,1); dydt(1) = F*x(1) - G*x(1)*x(2); dydt(2) = (F-G)*x(2); end I would like my code to work such that when the system has reached steady-state, the value of F is changed to 10 and the value of G

Scipy ODE time steps going backward

时光毁灭记忆、已成空白 提交于 2019-12-12 15:06:20
问题 I've looked around on Stackoverflow, but could not find anything that would answer my question. Problem Setup: I am trying to solve a system of stiff ODEs using scipy.integrate.ode . I've reduced the code to the minimal working example: import scipy as sp from scipy import integrate import matplotlib.pylab as plt spiketrain =[0] syn_inst = 0 def synapse(t, t0): tau_1 = 5.3 tau_2 = 0.05 tau_rise = (tau_1 * tau_2) / (tau_1 - tau_2) B = ((tau_2 / tau_1) ** (tau_rise / tau_1) - (tau_2 / tau_1) **

Solving ODEs - only positive solutions

送分小仙女□ 提交于 2019-12-12 14:27:23
问题 I am trying to to solve ODEs restricted to positive solutions, i.e.: dx/dt=f(x) with x>=0 . In MATLAB this is very easy to implement. Is there any workaround or package for R to restrict the solution-space to positive values only? This is very crucial in my case and unfortunately there is no alternative. I searched for a while now but without any success. :-( 回答1: There's still not quite enough to go on here. For the sorts of problems I'm familiar with, modifying the system to operate on the

Matlab - solving a third order differential equation

一笑奈何 提交于 2019-12-12 10:41:38
问题 y''' + 41y'' + 360y' + 900y = 600x' + 1200x; y(0)= 2 ; y'(0)= 1 ; y''(0) = -0.05 How can I solve this equation using the ODE45 function? I tried this: ==> function dydt=f(t,y) dydt = [y(2) ; y(3) ; -41*y(3)-360*y(2)- 900*y(1)] ==> clear all; timerange=[0 1.4]; %seconds initialvalues=[2 1 -0.05]; [t,y]=ode45(@dydt, timerange, initialvalues) plot(t,y(:,1)); But I need put the X part in the equation - I don't know how... 回答1: To use ODE45 (or similar) you need to convert the third order ODE into

Vectorization of Matlab Code involving ODE solver at each iteration

微笑、不失礼 提交于 2019-12-12 05:15:47
问题 I want to write a fast MATLAB code where I need to write a for loop and I need to solve an ordinary differential equation each time.Is there any way to vectorize the code? Following is the part of the code: tspan=0:0.01:20; dw=rand(p,1); M0=repmat([0 0 1],p,1)'; for p=1:ns [t,M(:,:,p)]=ode45(@(t,M) testfun(t,M,dw(p)),tspan,M0(:,p)); end where function dM=testfun(t,M,w1) M_x=M(1); M_y=M(2); M_z=M(3); dM=[w1*M_y;-w1*M_x+w1*M_z-2*w1*M_y;-w1*M_y-(1-M_z)]; 回答1: Try this and let me know how it

matlab for loop within ode solver

北慕城南 提交于 2019-12-12 04:55:52
问题 i am using ODE solver for solving my system of ODE. Now i also want to calculate sensitivity of various parameters by varying them. My basic ODE solver program is something like: Function: function F = ODE_site(t,y) %%Parameter block k1f=1e8; k1b=1e5; %%and so on %%Elementary rate block r1=k1f*y(1)-k1b*P*y(5); and so on %%Mass balance block F=[ r1-r5-r78+r86 ; and so on ]; %% End of function The main ODE solver looks like: optode = odeset('NonNegative',1:41,'Abstol',1E-20,'RelTol',1E-20); y0

Error using ode45 and deval

不想你离开。 提交于 2019-12-12 04:53:52
问题 I am trying to integrate a set of ordinary differential equations and calculate the solution and its first order derivative at given points. Matlab provides "ode45" to solve the equations and "deval" to calculate the solution and its first derivative, however, I am not able to use them in my case. Matlab gives the following example: sol = ode45(@vdp1,[0 20],[2 0]); x = linspace(0,20,100); y = deval(sol,x,1); plot(x,y); where I guess "vdp1" has been defined by Matlab and this example worked

trying to solve 2 first order differential equations, python

孤人 提交于 2019-12-12 01:49:15
问题 I am trying to solve these 2 equations bellow and I am having no luck, if anyone can point out where i am going wrong that would be great thanks! def f(t,alpha): return t*t/(2*alpha) * (1-sqrt(1-4*alpha)) def f_1 (t,x,params): alpha=params[0] return [X[1],-((3/f(t,alpha)*X[0]))] T=ode_solver() T.y_0=[1,0] T.function=f_1 T.scale_abs=[1e-4,1e-4,1e,-5] T.error_rel=1e-4 T.ode_solve(t_span[0,1000],params=[0.001],num_points=1000) T.plot_solution(i=0) 回答1: Try using scipy. Look this example: from

python non linear ODE with 2 variables

有些话、适合烂在心里 提交于 2019-12-12 01:26:14
问题 I am trying to solve the Brusselator model, a non-linear ODE, using python. I used to do this with MATLAB but now am building an application with python as a backend. That's why I want to switch ti python. dx/dt = A + (x^2)(y) - Bx - x dy/dt = Bx - (x^2)(y) I have checked stackoverflow and most of examples I found are simple non-linear ODE with a single variable that can be converted into a system of linear equation. [- Sorry for my notation. I don't know how to add latex in stackoverflow]

Scilab: How to solve an ODE where dy/dt = filter(1, ar, y1)

和自甴很熟 提交于 2019-12-11 17:03:13
问题 I want to simulate a time series y1 with an AR(p) process, and then solve the differential equation dy/dt = AR(p)(y1) . This is the Scilab code I wrote (the AR coefficients are calculated with the lev() function and then normalized in a part of the code I omitted to keep it short). t = [0:0.1:2*%pi]; y1 = sin(t); C = 1; y2 = -1*cos(t) + C; ar = [1. - 0.0195380 - 0.0154317 - 0.0116690 - 0.0081661 -0.1015448] y1_m = filter(1, ar, y1); //Generates simulated series function y_m = far(t, y, ar, y1