differential-equations

Sympy: solving differential equation with initial conditions error

落爺英雄遲暮 提交于 2021-02-19 08:09:07
问题 Since Sympy version 1.2, python Sympy has implemented the ability to solve for the constants in a simple differential equation, given some initial conditions. I was trying to test out this feature, but keep getting an error that I don't know how to solve. The documentation indicates the following format for initial conditions, and I tried to follow what was specified in the actual pull request that implemented the feature. Here is the code and the error. import sympy as sp t = sp.symbols('t')

Python implementation of n-body problem issue

筅森魡賤 提交于 2021-02-16 08:59:07
问题 I am currently trying to implement the N-body problem using Euler's method for solving differential equations. However, the graphical outputs do not seem correct, and I'm not sure where the issue in my code is after a while of testing. I'm currently using approximate values for Alpha Centauri A and B to test. This is my code: import numpy as np import matplotlib.pyplot as plt from math import floor # gravitation constant G = 6.67430e-11 # astronomical units au = 1.496e11 sec_in_day = 60 * 60

solve_ivp differential equation solver, way to not integrate all return values?

断了今生、忘了曾经 提交于 2021-02-11 12:31:59
问题 Hey i have a model which gives diferential return values. But also a value which isnt a differential (z) def model(t, f): x = f[0] y = f[1] dx_dt = 2x*y dy_dt = x**3 z = 2*x return dx_dt, dy_dt, z My solver can solve this equations and give me x and y at the respective time values. t = np.linspace(0, 10, 100) f0 = [2, 1, 0] result = solve_ivp(model, [np.min(t), np.max(t)], f0, t_eval=t) But now i want also my solution for z which should NOT be integrated by the solver. Is there any

Fourth-order Runge–Kutta method (RK4) collapses after a few iterations

微笑、不失礼 提交于 2021-02-10 18:02:10
问题 I'm trying to solve: x' = 60*x - 0.2*x*y; y' = 0.01*x*y - 100* y; using the fourth-order Runge-Kutta algorithm. Starting points: x(0) = 8000, y(0) = 300 range: [0,15] Here's the complete function: function [xx yy time r] = rk4_m(x,y,step) A = 0; B = 15; h = step; iteration=0; t = tic; xh2 = x; yh2 = y; rr = zeros(floor(15/step)-1,1); xx = zeros(floor(15/step)-1,1); yy = zeros(floor(15/step)-1,1); AA = zeros(1, floor(15/step)-1); while( A < B) A = A+h; iteration = iteration + 1; xx(iteration)

How to implement dynamic parameter estimation with missing data in Gekko?

早过忘川 提交于 2021-02-10 16:00:34
问题 Going back and forth through the documentation, I was able to set-up a dynamic parameter estimation in Gekko. Here's the code, with measurement values shown below (the file is named MeasuredAlgebrProductionRate_30min_18h.csv on my system, and uses ; as separator): import numpy as np import matplotlib.pyplot as plt from gekko import GEKKO #%% Read measurement data from CSV file t_x_q_obs = np.genfromtxt('MeasuredAlgebrProductionRate_30min_18h.csv', delimiter=';') #t_obs, x_obs, q_obs = t_xq

How to implement dynamic parameter estimation with missing data in Gekko?

风流意气都作罢 提交于 2021-02-10 15:59:07
问题 Going back and forth through the documentation, I was able to set-up a dynamic parameter estimation in Gekko. Here's the code, with measurement values shown below (the file is named MeasuredAlgebrProductionRate_30min_18h.csv on my system, and uses ; as separator): import numpy as np import matplotlib.pyplot as plt from gekko import GEKKO #%% Read measurement data from CSV file t_x_q_obs = np.genfromtxt('MeasuredAlgebrProductionRate_30min_18h.csv', delimiter=';') #t_obs, x_obs, q_obs = t_xq

Solving a system of 2nd order differential equations from sympy

。_饼干妹妹 提交于 2021-02-10 14:50:39
问题 I am doing a multiple DOF dynamics problem, using 2nd order Lagrangian equations. I used sympy to get to the equations of motion. Now these equations after calculating the derivatives got quite long, seems though that sympy simplify cant simplify it further. My problem actually is how to solve this system of three 2nd order ode from here. I don't know how to get these equations converted so they can be used with scipy.odeint(). Substitution came to mind, but there are a lot of symbols. So Im

How can I run a simple parallel array assignment operation in Julia?

好久不见. 提交于 2021-02-10 14:03:34
问题 I have to solve a differential equations system many times, iterating over a parameter. For this, I run a loop over a list of the parameter, and store the solution (evaluated at an array of time values) for each parameter. So I have a 2D array in which I store solutions (each row is for a value of the parameter). Now, since any iteration has nothing to do with another one, I thought of doing this in parallel. Here is my code: using DifferentialEquations using SharedArrays using DelimitedFiles

How can I run a simple parallel array assignment operation in Julia?

蓝咒 提交于 2021-02-10 14:02:08
问题 I have to solve a differential equations system many times, iterating over a parameter. For this, I run a loop over a list of the parameter, and store the solution (evaluated at an array of time values) for each parameter. So I have a 2D array in which I store solutions (each row is for a value of the parameter). Now, since any iteration has nothing to do with another one, I thought of doing this in parallel. Here is my code: using DifferentialEquations using SharedArrays using DelimitedFiles

What is the theory behind the odeintw package for complex matrix differential equations?

帅比萌擦擦* 提交于 2021-02-08 09:53:38
问题 In most of the below answers for complex matrix differential equations, the odeintw package has been suggested. https://stackoverflow.com/a/45970853/7952027 https://stackoverflow.com/a/26320130/7952027 https://stackoverflow.com/a/26747232/7952027 https://stackoverflow.com/a/26582411/7952027 I want to know the theory behind the manipulations done in the code of odeintw. Like why one has to build that banded jacobian, the idea behind the functions _complex_to_real_jac, _transform_banded_jac,