ode

Runge-Kutta 4th order method to solve second-order ODES

限于喜欢 提交于 2021-02-08 02:07:24
问题 I am trying to do a simple example of the harmonic oscillator, which will be solved by Runge-Kutta 4th order method. The second-order ordinary differential equation (ODE) to be solved and the initial conditions are: y'' + y = 0 y(0) = 0 and y'(0) = 1/pi The range is between 0 and 1 and there are 100 steps. I separated my 2nd order ODE in two first-order ODEs, using u as auxiliary variable: y' = u u' = -y The analytical solution is sinusoidal y(x) = (1/pi)^2 sin(pi*x). My Python code is below:

Runge-Kutta 4th order method to solve second-order ODES

夙愿已清 提交于 2021-02-08 02:03:43
问题 I am trying to do a simple example of the harmonic oscillator, which will be solved by Runge-Kutta 4th order method. The second-order ordinary differential equation (ODE) to be solved and the initial conditions are: y'' + y = 0 y(0) = 0 and y'(0) = 1/pi The range is between 0 and 1 and there are 100 steps. I separated my 2nd order ODE in two first-order ODEs, using u as auxiliary variable: y' = u u' = -y The analytical solution is sinusoidal y(x) = (1/pi)^2 sin(pi*x). My Python code is below:

How to rewrite Maple code to Matlab, functions fsolve() and solve()?

你离开我真会死。 提交于 2021-02-05 12:21:11
问题 I have an ordinary differential equation (ODE) -- Van Der Pol oscillator Problem: y''-2a (1-y^2)y'+y=0, y(0)=0, y'(0)=0.5, x in [0,10], a =0.025. The ODE was solved on Maple Software with the fsolve() function. I need to rewrite the code on Matlab (version R2013a). My attempt is below. n = 0 h = 0.1 syms z0; % z in point 0 syms y0; % z in point 0 f0 = 2 * 0.025 * z0 - 2 * 0.025 * ((y0)^2) * z0 - y0 syms z1; % z in point 1 syms y1; % z in point 1 f1 = 2 * 0.025 * z1 - 2 * 0.025 * ((y1)^2) * z1

Solving vector second order differential equation while indexing into an array

断了今生、忘了曾经 提交于 2021-02-05 11:26:27
问题 I'm attempting to solve the differential equation: m(t) = M( x ) x'' + C( x , x' ) + B x' where x and x' are vectors with 2 entries representing the angles and angular velocity in a dynamical system. M( x ) is a 2x2 matrix that is a function of the components of theta, C is a 2x1 vector that is a function of theta and theta' and B is a 2x2 matrix of constants. m(t) is a 2*1001 array containing the torques applied to each of the two joints at the 1001 time steps and I would like to calculate

Solve complex matrix differential equation with Odeint

瘦欲@ 提交于 2021-02-04 21:13:47
问题 I want to solve a matrix differential equation, like this one: import numpy as np from scipy.integrate import odeint def deriv(A, t, Ab): return np.dot(Ab, A) Ab = np.array([[-0.25, 0, 0], [ 0.25, -0.2, 0], [ 0, 0.2, -0.1]]) time = np.linspace(0, 25, 101) A0 = np.array([10, 20, 30]) MA = odeint(deriv, A0, time, args=(Ab,)) However, this does not work in the case of having complex matrix elements. I am looking for something similar to scipy.integrate.complex_ode but for odeint . If this is not

Solve complex matrix differential equation with Odeint

♀尐吖头ヾ 提交于 2021-02-04 21:12:51
问题 I want to solve a matrix differential equation, like this one: import numpy as np from scipy.integrate import odeint def deriv(A, t, Ab): return np.dot(Ab, A) Ab = np.array([[-0.25, 0, 0], [ 0.25, -0.2, 0], [ 0, 0.2, -0.1]]) time = np.linspace(0, 25, 101) A0 = np.array([10, 20, 30]) MA = odeint(deriv, A0, time, args=(Ab,)) However, this does not work in the case of having complex matrix elements. I am looking for something similar to scipy.integrate.complex_ode but for odeint . If this is not

Unsure about how to use event function in Matlab

眉间皱痕 提交于 2021-01-29 14:39:56
问题 I am trying to plot a state-space diagram, as well as a time-history diagram, of a dynamical system. There's a catch, though. The state-space is divided into two halves by a plane located at x1 = 0. The state-space axes are x1, x2, x3. The x1 = 0 plane is parallel to the x2/x3 plane. The state-space above the x1 = 0 plane is described by the ODEs in eqx3, whereas the state-space below the x1 = 0 plane is described by the ODEs in eqx4. So, there is a discontinuity on the plane x1 = 0. I have a

How to include time dependent variables into ode-solver in Scilab?

牧云@^-^@ 提交于 2021-01-29 11:23:13
问题 I am currently solving a system of nonlinear ODE's. It is a set of kinematic motion equations, where I need to calculate the position angles with given anguar velocities I found out, how to add a function dependent on time using the list, but the question is, how to add a parameter which is also time dependent, but given as a vector. Simplified is it written in the following code. c(t) is a time function. function dx = f(t, x, c) dx(1) = x(1)*sin(x(2)) dx(2) = c*x(2)*cos(x(1)) dx(3) = t*cos(x

Runge-Kutta 4th order to solve 2nd order ODE system using Python

旧街凉风 提交于 2021-01-29 07:44:25
问题 I'm trying to solve system of two odes numerically by runge-kutta 4th order method. initial system: system to solve: And I have very strange solution graph... I have: Correct graph: I can't find trouble in my runge-kutta. Please, help me. My code is here: dt = 0.04 #initial conditions t.append(0) zdot.append(0) z.append(A) thetadot.append(0) theta.append(B) #derrive functions def zdotdot(z_cur, theta_cur): return -omega_z * z_cur - epsilon / 2 / m * theta_cur def thetadotdot(z_cur, theta_cur)

Difficulty running an ODE model in R including a parameter that varies by time (forcing function)

强颜欢笑 提交于 2021-01-28 15:04:47
问题 I am trying to fit a reasonably basic ODE model using deSolve, including within the model a parameter that varies by time (force of infection; FOI). While running the model without this parameter works fine, inclusion of the time dependent parameter gives an error (see below). I am relatively new to R and mathematical modelling, and have been trying to solve this problem for some time now. I have created the FOI parameter as a matrix of values and then used the approxfun function for