ode

How to solve this differential equation using scipy odeint?

﹥>﹥吖頭↗ 提交于 2019-12-02 04:29:49
I am trying to solve the following differential equation using scipy odeint without much success: import numpy as np from scipy.misc import derivative from scipy.integrate import odeint Imag = 16000. w = 2*np.pi*60 tau = .05 theta = 1.52 phi = theta - np.radians(90) t = np.linspace(0,.1,10000) def Ip(t): return np.sqrt(2)*Imag*(np.sin(w*t+phi-theta)-np.exp(-t/tau)*np.sin(phi-theta)) B = lambda Ip: Ip/(53.05+0.55*abs(Ip)) def L(B): return derivative(B,Ip(t))*377.2 def dI(t): return derivative(Ip,t) def f(y,t): Rb = 8. N = 240. Is = y[0] f0 = (1/(L(B)+0.002))*((dI(t)*L(B)/N)-Rb*y[0]) return [f0]

How can I solve an ODE without using nested functions?

穿精又带淫゛_ 提交于 2019-12-01 23:42:39
问题 I have some differential equations that I need to solve using MATLAB's ODE solvers. While the differential equations themselves are fairly simple, they depend on a lot of "constants". These constants aren't universal, and need to be supplied by the caller. An example ODE of this sort would be: dx/dt = -j * (k + x) ./ (l + x) Where j, k and l are constants and x is a variable. The way I have been solving these so far is to use a function that takes in all the initial values and all the values

MatLab ODE start/stop conditions

…衆ロ難τιáo~ 提交于 2019-12-01 12:34:44
I have a small problem. I have 2 equation of motion 'ph' and 'ph2' I don´t know how to set ODE to stop calculating 'ph' when x(1)> 0.111 and then starts to calculated 'ph2' again only to 0.111, after that plot 'ph' + 'ph2' to one graph depend on time 'w' i think I have to set some time limitations but dont know how to. I use HELP but no benefit for me. [t,y] = ode45(@ph,[0,w_max],[0,0]); function dx = ph(tt,x) global F1 c m_c Ff p w s ln f_t sig dstr Ren pn Fex Fzmax xz xn l Fz mn Fpp = F1 + c*x(1); if pn<0 pn=abs(pn); end if x(1)<ln pn=spline(w,p,tt)-((2*sig)/dstr*Ren); Fex=3.1416.*f_t.*pn.*

MatLab ODE start/stop conditions

我的未来我决定 提交于 2019-12-01 11:17:13
问题 I have a small problem. I have 2 equation of motion 'ph' and 'ph2' I don´t know how to set ODE to stop calculating 'ph' when x(1)> 0.111 and then starts to calculated 'ph2' again only to 0.111, after that plot 'ph' + 'ph2' to one graph depend on time 'w' i think I have to set some time limitations but dont know how to. I use HELP but no benefit for me. [t,y] = ode45(@ph,[0,w_max],[0,0]); function dx = ph(tt,x) global F1 c m_c Ff p w s ln f_t sig dstr Ren pn Fex Fzmax xz xn l Fz mn Fpp = F1 +

Saving derivative values in ode45 in Matlab

两盒软妹~` 提交于 2019-12-01 09:38:49
I'm simulating equations of motion for a (somewhat odd) system with mass-springs and double pendulum, for which I have a mass matrix and function f(x), and call ode45 to solve M*x' = f(x,t); I have 5 state variables, q= [ QDot, phi, phiDot, r, rDot]'; (removed Q because nothing depends on it, QDot is current.) Now, to calculate some forces, I would like to also save the calculated values of rDotDot, which ode45 calculates for each integration step, however ode45 doesn't give this back. I've searched around a bit, but the only two solutions I've found are to a) turn this into a 3rd order

Solve ODE in Python with a time-delay

北城以北 提交于 2019-11-30 22:52:20
Can anybody give me some advice how to solve an ODE in Python that has a time-delay implemented in it? I can't seem to figure out how to do it using scipy.integrate.odeint. What I am looking for should look like: # the constants in the equation b = 1/50 d = 1/75 a = 0.8 G = 10 ** (-2) tau = 0.5 u = [b, d, tau, a, G] # enter initial conditions N0 = 0.1 No0 = 10 w = [N0, No0] def logistic(w, t, u): N, No = w b, d, tau, a, G = u dNdt = b * (No(t) - N(t) ) * (N(t) / No(t) ) - d * N(t - tau) dNodt = G * (a * No(t) - N(t) ) * (N(t) / No(t) ) return [dNdt, dNodt] # create timescale # create timescale

c# - solving complexed ODE set

我的梦境 提交于 2019-11-30 20:41:30
问题 Introduction Some sets od ODE can't be solved analytically. In this case there are plenty of well-know methods, especially in typical scientific software like MATLAB. As long as you stay with it, all is fine. But the problem starts if you try to port this functionality to other environment. In my case I need it in C#. Some details Of course, there are some C# libs for ODE's but in most cases (at least in this which i'm familiar with), there are quite limited. Let's look at OSLO library, here

Solve ODE in Python with a time-delay

北战南征 提交于 2019-11-30 15:48:40
问题 Can anybody give me some advice how to solve an ODE in Python that has a time-delay implemented in it? I can't seem to figure out how to do it using scipy.integrate.odeint. What I am looking for should look like: # the constants in the equation b = 1/50 d = 1/75 a = 0.8 G = 10 ** (-2) tau = 0.5 u = [b, d, tau, a, G] # enter initial conditions N0 = 0.1 No0 = 10 w = [N0, No0] def logistic(w, t, u): N, No = w b, d, tau, a, G = u dNdt = b * (No(t) - N(t) ) * (N(t) / No(t) ) - d * N(t - tau) dNodt

Pass args for solve_ivp (new SciPy ODE API)

不羁岁月 提交于 2019-11-30 08:43:32
For solving simple ODEs using SciPy, I used to use the odeint function, with form: scipy.integrate.odeint(func, y0, t, args=(), Dfun=None, col_deriv=0, full_output=0, ml=None, mu=None, rtol=None, atol=None, tcrit=None, h0=0.0, hmax=0.0, hmin=0.0, ixpr=0, mxstep=0, mxhnil=0, mxordn=12, mxords=5, printmessg=0)[source] where a simple function to be integrated could include additional arguments of the form: def dy_dt(t, y, arg1, arg2): # processing code here In SciPy 1.0, it seems the ode and odeint funcs have been replaced by a newer solve_ivp method. scipy.integrate.solve_ivp(fun, t_span, y0,

Stop integration after designated length of time in Matlab

孤者浪人 提交于 2019-11-29 17:43:14
I want to stop solving a differential equation in Matlab if it takes more than a designated amount of time. I tried the following,but it doesn't work... options = odeset('AbsTol',1e-8,'RelTol',1e-5); RUNTIME=5; timerID = tic; while (toc(timerID) < RUNTIME) [t_pae,x_th_pae] = ode15s(@prosomoiwsh,[0 t_end],[80*pi/180;0;130*pi/180;0;th_initial(1);th_initial(2);th_initial(3);th_initial(4)],options); end How can I solve this? UPDATE : I tried what horchler suggested and now my code looks like this : interupt_time = 20; outputFun= @(t,y,flag)interuptFun(t,y,flag,interupt_time); options = odeset(