differential-equations

Solving a BVP using scipy.solve_bvp where the function returns an array

ε祈祈猫儿з 提交于 2019-12-11 14:07:35
问题 This is a very general question as I feel that my errors are resulting from some misunderstanding of how scipy.solve_bvp works. I have a function def that takes an array of 12 numbers and returns a list of the system of differential equations for a given time, with shape (2,6). I will have a one dimensional array of length n for my timesteps and then an array y of input values with shape (12,n). My code aims to take simulate the motion of earth and mars over a 1000 day period subject to

Matlab - “Could not extract differential variables to solve for” in dsolve

醉酒当歌 提交于 2019-12-11 12:25:05
问题 I am trying to solve a RLC circuit as a symbolic differential equation in MATLAB using dsolve , the equation being U(t) = L*Q''(t) + R*Q'(t) + (1/C)*Q(t) with the initial conditions Q(0) = 0 Q'(0) = 0 and U(t) = 10*sin(2*t) L = 1 R = 0 C = 1/4 While this works ... When I implement it explicitly (and using strings) as Q = dsolve('D2Q(t) + 4*Q(t) = 10*sin(2*t)', 'DQ(0)=0, Q(0)=0'); Q = simplify(Q); I'll get Q = 5 sin(2 t) 5 t cos(2 t) ---------- - ------------ 4 2 which is correct. ... this

Solve variable coefficients second order linear ODE?

我们两清 提交于 2019-12-11 10:19:01
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 6 years ago . For the variable coefficients second order linear ODE $x''(t)+\beta_1(t)x'(t)+\beta_0 x(t)=0$ I have the numerical values (in terms of vectors) for $\beta_1(t)$ and $\beta_0(t)$, does anyone know some R package to do that? And some simple examples to illustrate would be great as well. I googled to find 'bvpSolve' can solve constant coefficients value. 回答1: In order to use

How do I solve a second order differential equation in R?

允我心安 提交于 2019-12-11 08:10:13
问题 I am learning R to solve a second order differential equation(probably using deSolve package). Which I have written in python by writing it as two first order differential equations and is given below import numpy as np import matplotlib.pyplot as plt from scipy.integrate import odeint def fun(X, t): y , dy , z = X M = np.sqrt (1./3. * (1/2. * dy **2 + 1./2. * y **2)) dz = (M*z) # dz/dt ddy = -3.* M * dy - y # ddy/dt return [dy ,ddy ,dz] y0 = 1 dy0 = -0.1 z0 = 1. X0 = [y0, dy0, z0] M0 = np

Pendulum simulation in Python using odeint() not quite working as a pendulum

流过昼夜 提交于 2019-12-11 06:28:08
问题 I have built a pendulum simulation using fourth order Runge-Kutta differentiation where everything is done step by step: from scipy import * from matplotlib.pyplot import * ##A pendulum simulation using fourth order ##Runge-Kutta differentiation ts=.05 #time step size td=20 #trial duration te=int(td/ts) #no of timesteps mu=0.1 #friction factor m=1 #mass g=9.81 #grav. acceleration l=1 #length th=[((rand()*2)-1)*pi] #initial angle om=[0] #initial angular velocity u=0 #torque for j in range(te):

using scipy solve_ivp for a function with extra arguments

本小妞迷上赌 提交于 2019-12-11 04:23:29
问题 I am trying to solve an initial value problem with solve_ivp. The problem is that my function f(x,y)=dy/dx contain extra arguments. I tried to use this: Pass args for solve_ivp (new SciPy ODE API) but it keeps giving me errors. Here is the code: from numpy import arange import math import numpy as np from scipy.integrate import solve_ivp from numpy import pi sigmav = 1.0e-9 Mpl = 1.22e19 ms=100.0 gg=100.0 gs=106.75 def Yeq(x): return 0.145*(gg/gs)*(x)**(3/2)*np.exp(-x) def ss(x,m_dm): return

solving system of ode using matlab

两盒软妹~` 提交于 2019-12-11 03:10:48
问题 I have 9 equations with a time dependent coefficient g % MY M file function dy =tarak(t,y) G= 3.16; g = 0.1*exp(-((t-200)/90).^2); dy=zeros(9,1); dy(1)=-2*2*y(1)+2*G*y(5)+2*g*y(7); dy(2)=2*y(1)-2*G*y(5); dy(3)=2*y(1)-2*g*y(7); dy(4)=-2*y(4)+g*y(9); dy(5)=-2*y(5)+G*(y(2)-y(1))+g*y(8); dy(6)=-2*y(6)-G*y(9); dy(7)=-2*y(7)+g*(y(3)-y(1))+G*y(8); dy(8)=-G*y(7)-g*y(5); dy(9)=G*y(6)-g*y(4); then in command window: [T,Y] = ode45(@tarak,[0 ,500],[0 0 1 0 0 0 0 0 0]) where coefficient G = 3.16 and g = 0

Python solve delay differential equations conditionally

拜拜、爱过 提交于 2019-12-11 02:56:48
问题 I am using dde23 of pydelay package to solve a delay differential equation. My question: How to code a equation conditionally? For example the target equation has two options: when x>1, dx/dt=0.25 * x(t-tau) / (1.0 + pow(x(t-tau),10.0)) -0.1*x otherwise, dx/dt=0.25 * x I tried two approaches, but it seems like neither one worked: Approach 1 did not complain, but it the if else statement has not been interpreted. Approach 2 generated the following errors: Found executable c:\mingw\bin\g++.exe

Scipy odeint Non-negative solution

心不动则不痛 提交于 2019-12-11 02:42:53
问题 Apparently, getting a non-negative solution from an ODE solver is non-trivial. In Matlab, there is the NonNegative option for certain solvers to get a non-negative solution. Is there a similar option in scipy? If not, what is the "best" way of imposing a non-negativity constraint? At the moment, I have something like the following: def f(x, t, params): ... ... ... ... ... ... x_dot[(x <= 0) * (x_dot <= 0)] = 0.0 return x_dot ... ... ... x = odeint(f, x0, t, args=params) However, this leads to

How to get Rosenbrock23 to work with ODE in ParameterizedFunctions.jl DSL?

*爱你&永不变心* 提交于 2019-12-11 02:28:04
问题 Further to this question, I have the same model implemented in ParameterizedFunctions.jl DSL. The following MWE works: using DifferentialEquations using Plots # Modeling a consecutive / parallel reaction in a CSTR # A --> 2B --> C, C --> 2B, B --> D # PETERSEN-Matrix # No. A B C D Rate # 1 -1 2 k1*A # 2 -2 1 k2*B*B # 3 2 -1 k3*C # 4 -1 1 k4*B fpr! = @ode_def ConsecutiveParallelReaction begin dA = -k_1*A + q_in/V_liq*(A_in - A) dB = 2*k_1*A - 2*k_2*B*B + 2*k_3*C - k_4*B + q_in/V_liq*(B_in - B)