ode

matlab ode45 retrieving parameters

时光怂恿深爱的人放手 提交于 2020-01-04 02:55:31
问题 I'm experimenting with ode45 in Matlab. I've learned how to pass parameters to the ode function but I still have a question. Let's suppose that I want to compute the trajectory (speed profile) of a Car and I have a function, e.g. getAcceleration , that gives me the acceleration of the car but also the right gear: [acceleration, gear] = getAcceleration(speed,modelStructure) where modelStructure represents the model of the car. The ode function would be: function [dy] = car(t,y,modelStructure)

Changing parameters within function for use with ODE solver

余生颓废 提交于 2020-01-03 05:47:10
问题 Is is it possible to use an ODE solver, such as ode45, and still be able to 'change' values for the parameters within the called function? For example, if I were to use the following function: function y = thisode(t, Ic) % example derivative function % parameters a = .05; b = .005; c = .0005; d = .00005; % state variables R = Ic(1); T = Ic(2); y = [(R*a)-(T/b)+d; (d*R)-(c*T)]; with this script: clear all % Initial conditions It = [0.06 0.010]; % time steps time = 0:.5:10; % ODE solver [t,Ic1]

How to draw the direction field of van der pol oscillator?

雨燕双飞 提交于 2020-01-03 02:08:25
问题 I am trying to get the direction field and phase portrait shown on this wiki page: Van der Pol oscillator in wikipedia My code: options = odeset('MaxStep',0.5); temp = inputdlg('Enter mu value'); mu = str2double(temp{1,1}); [t,y] = ode45(@(t,y) vdp1_1(t,y,mu),[0 10],[2; 0],options); plot(y(:,1),y(:,2)); hold on quiver(y(:,1), y(:,2), gradient(y(:,1)), gradient(y(:,2) )) hold off function dydt = vdp1_1(t,y,mu) dydt = zeros(2,1); dydt(1) = y(2); dydt(2) = [mu * (1-y(1)^2)*y(2)-y(1)]; end

Python: Unable to solve a differential equation using odeint with signum function

[亡魂溺海] 提交于 2020-01-02 06:52:21
问题 I am trying to solve this problem: where U is here: s=c*e(t)+e_dot(t) and e(t)=theta(t)-thetad(t) and e_dot(t)=theta_dot(t)-thetad_dot(t) where thetad(theta desired)=sin(t)-- i.e signal to be tracked! and thetad_dot=cos(t),J=10,c=0.5,eta=0.5 I tried first with odeint- it gave error after t=0.4 that is theta(solution of above differential equation) fell flat to 0 and stayed thereafter. However when I tried to increase mxstep to 5000000 I could get somewhat correct graph till t=4.3s. I want to

Does scipy.integrate.ode.set_solout work?

眉间皱痕 提交于 2019-12-28 18:06:05
问题 The scipy.integrate.ode interface to integration routines provides a method for stopping the integration if a constraint is violated at any step, set_solout . However, I cannot get this method to work, even in the simplest examples. Here's one attempt: import numpy as np from scipy.integrate import ode def f(t, y): """Exponential decay.""" return -y def solout(t, y): if y[0] < 0.5: return -1 else: return 0 y_initial = 1 t_initial = 0 r = ode(f).set_integrator('dopri5') # Integrator that

How solve a system of ordinary differntial equation with time-dependent parameters

孤人 提交于 2019-12-28 04:28:05
问题 How solve a system of ordinary differential equation ..an initial value problem ....with parameters dependent on time or independent variable? say the equation I have Dy(1)/dt=a(t)*y(1)+b(t)*y(2); Dy(2)/dt=-a(t)*y(3)+b(t)*y(1); Dy(3)/dt=a(t)*y(2); where a(t) is a vector and b(t) =c*a(t); where the value of a and b are changing with time not in monotone way and each time step. I tried to solve this using this post....but when I applied the same principle ...I got the error message "Error using

Absolute error of ODE45 and Runge-Kutta methods compared with analytical solution

夙愿已清 提交于 2019-12-28 02:53:05
问题 I would appreciate if someone can help with the following issue. I have the following ODE: dr/dt = 4*exp(0.8*t) - 0.5*r ,r(0)=2, t[0,1] (1) I have solved (1) in two different ways. By means of the Runge-Kutta method (4th order) and by means of ode45 in Matlab. I have compared the both results with the analytic solution, which is given by: r(t) = 4/1.3 (exp(0.8*t) - exp(-0.5*t)) + 2*exp(-0.5*t) When I plot the absolute error of each method with respect to the exact solution, I get the

Using adaptive time step for scipy.integrate.ode when solving ODE systems

浪子不回头ぞ 提交于 2019-12-25 08:08:19
问题 I have to just read Using adaptive step sizes with scipy.integrate.ode and the accepted solution to that problem, and have even reproduced the results by copy-and-paste in my Python interpreter. My problem is that when I try and adapt the solution code to my own code I only get flat lines. My code is as follows: from scipy.integrate import ode from matplotlib.pyplot import plot, show initials = [1,1,1,1,1] integration_range = (0, 100) f = lambda t,y: [1.0*y[0]*y[1], -1.0*y[0]*y[1], 1.0*y[2]*y

Solving ODE with deSolve in R- number of derivatives error

﹥>﹥吖頭↗ 提交于 2019-12-25 04:23:15
问题 I am trying to use the deSolve package for a set of ODE's with equations as auxiliary variables. I keep getting the error where the number of derivatives isn't the same length as the initial conditions vector. What should I change? # rm(list=ls()) library(deSolve) exponential=function(t,state,parameters){ with(as.list( c(state,parameters)), { #Aux. Var. fX2 = pmax(0,1-(1-(d2/r12)*(X2/K2))) fX1 = X1/(X1+k1); # equations (ODE) dX1 = C-((d1)*(X1))-(r12)*(X2)*fX2*fX1 # differential equaion dX2 =

odeint returns wrong results for an ODE including descrete function

妖精的绣舞 提交于 2019-12-25 01:44:57
问题 I'm trying to model the ODE: I implemented: import numpy as np from scipy.integrate import odeint import matplotlib.pyplot as plt m = 1 k = 1 M = 0.1 b = 1 Fmax = 1 def dXdt(X,t): return [X[1], - b * X[1] / m - k * X[0] / m - M * np.sign(X[1]) / m + Fmax / m ] X0 = [1, 2] ts = np.linspace(0, 10, 200) Xs = odeint(dXdt, X0, ts) plt.plot(ts, Xs[:, 0]) resulting: which contradicts what I get from Modelica (OpenModelica): model model1 //constants parameter Real m = 1; parameter Real k = 1;