differential-equations

Matlab ode15s change parameter value at specific time during solution

白昼怎懂夜的黑 提交于 2019-12-24 09:09:01
问题 I'm trying to change the value of my variable Pin at specific points in time during the ode15s solution, in order to evaluate the dynamic response. But I get the error: Error using odearguments (line 83) The last entry in tspan must be different from the first entry. I believe the error is somewhere here: t_start=0; t=t_start; y=cond; while idx_seg< length(t_seg) idx_seg=idx_seg+1; t_end=t_seg(idx_seg); [t_sol,y_sol]=ode15s(@(t,y)f1_v1,[t_start, t_end],y(end,:)); t = [t; t_sol(2 : end)]; y =

Solving ODE with Simulink in Matlab

半城伤御伤魂 提交于 2019-12-24 03:07:56
问题 I need to solve this ODE using Simulink and I don't know how to make it. I only know how to do it using ODE solvers. y'' - y' - 2y = e^(3x) y(0)=1, y'(0)=2. I rewrote the equation obtaining an ODEs: y' = f(x,y) y(x0) = y0 y'1 = y2 y2= e^(3*x) + y' + 2y Using ODE solver. If someone can help me to solve this using a Simulink Model I would appreciate it. I know how to solve it in Matlab using ODE solvers as ode23 and ode23s but I don't know how to do it using a Simulink Model. Thanks in advance

ode solver event location index in MATLAB

瘦欲@ 提交于 2019-12-24 01:53:41
问题 Suppose I am trying to solve a system of differential equations using an ode solver in MATLAB. Suppose also that I have defined an events functions to locate three different events which are all terminal. I have noticed that on some occasions the ie quantity that is returned upon the location of one of the events ( ie is the index of the event that stopped the solver, in my case it could be 1, 2 or 3) is not always a single number but a vector with two elements (usually these elements are

How to use if statement in a differential equation (SciPy)?

浪子不回头ぞ 提交于 2019-12-21 20:20:12
问题 I am trying to solve a differential equation with Python. In this two system differential equation if the value of first variable ( v ) is more than a threshold (30) it should be reset to another value (-65). Below I put my code. The problem is that the value of first variable after reaching 30 remains constant and won't reset to -65. These equations describe the dynamics of a single neuron. The equations are taken from this website and this PDF file. import numpy as np import matplotlib

Help with symplectic integrators

流过昼夜 提交于 2019-12-20 09:59:43
问题 I'm trying to develop a physics simulation and I want to implement a fourth-order symplectic integration method. The problem is that I must be getting the math wrong, since my simulation is not working at all when using the symplectic integrator (as compared to a fourth-order Runge-Kutta integrator that works reasonably well for the simulation). I've been googling this forever and all I can find are scientific articles on the subject. I tried to adapt the method used in the articles, but am

Solving the Lorentz model using Runge Kutta 4th Order in Python without a package

孤者浪人 提交于 2019-12-18 07:11:50
问题 I wish to solve the Lorentz model in Python without the help of a package and my codes seems not to work to my expectation. I do not know why I am not getting the expected results and Lorentz attractor. The main problem I guess is related to how to store the various values for the solution of x,y and z respectively.Below are my codes for the Runge-Kutta 45 for the Lorentz model with 3D plot of solutions: import numpy as np import matplotlib.pyplot as plt #from scipy.integrate import odeint #a

How to evaluate the constants SymPy gives with initial condition?

让人想犯罪 __ 提交于 2019-12-18 05:12:43
问题 How can I evaluate the constants C1 and C2 from a solution of a differential equation SymPy gives me? There are the initial condition f(0)=0 and f(pi/2)=3. >>> from sympy import * >>> f = Function('f') >>> x = Symbol('x') >>> dsolve(f(x).diff(x,2)+f(x),f(x)) f(x) == C1*sin(x) + C2*cos(x) I tried some ics stuff but it's not working. Example: >>> dsolve(f(x).diff(x,2)+f(x),f(x), ics={f(0):0, f(pi/2):3}) f(x) == C1*sin(x) + C2*cos(x) By the way: C2 = 0 and C1 = 3. 回答1: There's a pull request

Finding the maxima of a function using ODE45

巧了我就是萌 提交于 2019-12-17 20:53:04
问题 I'm trying to locate the locations of one of the equations in a system of differential equations in MATLAB.I'm trying to use the Events propety of odeset.How do I pick out the particular equation in my function? options = odeset('Events',@event); [t x tm xm ie] = ode45(@Lorenz,[0 200],I,options); function X = Lorenz(t,x) r = 15; sigma = 10; b = 8/3; X(1,1) = sigma*(x(2,1)-x(1,1)); X(2,1) = r*(x(1,1)) - x(2,1) -x(1,1)*x(3,1); X(3,1) = x(1,1)*x(2,1) - b*x(3,1); end function [value,isterminal

How to plot solutions of system of nonlinear differential equations in MATLAB?

半世苍凉 提交于 2019-12-13 19:22:58
问题 I am trying to follow this research paper. I am trying to duplicate the graph of the solutions located in Figure 7 on page 20. I have a screenshot of Figure 7: I would first like to recreate the left picture. The system in question is what I have as dX . Here is what I have in an m-file: function dX = CompetitionModel(t,X) bs = 8*10^(-3); bl = 4*10^(-3); bh = 6.4*10^(-3); N = bs + bl + bh; K = 10^8; m1 = 2*10^(-5); m2 = 9*10^(-9); p = 5*10^(-13); I = 10^(-3); T = 0; a = 0; dX = [X(1) * (bs *

How to fix TypeError: in setindex! in DifferentialEquations.jl

跟風遠走 提交于 2019-12-13 03:57:19
问题 Recently, I got started with Julia's (v1.0.3) DifferentialEquations.jl package. I tried solving a simple ODE system, with the same structure as my real model, but much smaller. Depending on the solver which I use, the example either solves or throws an error. Consider this MWE, a Chemical Engineering model of a consecutive / parallel reaction in a CSTR: using DifferentialEquations using Plots # Modeling a consecutive / parallel reaction in a CSTR # A --> 2B --> C, C --> 2B, B --> D # PETERSEN