runge-kutta

Rk4 Integrator of a nonlinear second order ODE in Python

和自甴很熟 提交于 2020-12-26 20:02:25
问题 I'm in a project in my University and I have to implement the Runge-Kutta 4-order integrator using Python. I know I can use for example Sympy, but the goal here is implement the method, the code is ready written in Fortran language, so basically I have a data base with the correct values of solutions and I have to get similar solutions in my code. However, we have some problems; I did the same several times using linear equations ( first and second order ), however this is a second order

Rk4 Integrator of a nonlinear second order ODE in Python

给你一囗甜甜゛ 提交于 2020-12-26 19:58:20
问题 I'm in a project in my University and I have to implement the Runge-Kutta 4-order integrator using Python. I know I can use for example Sympy, but the goal here is implement the method, the code is ready written in Fortran language, so basically I have a data base with the correct values of solutions and I have to get similar solutions in my code. However, we have some problems; I did the same several times using linear equations ( first and second order ), however this is a second order

Lorenz attractor with Runge-Kutta python

吃可爱长大的小学妹 提交于 2020-12-15 13:28:34
问题 Hello I have to program a python function to solve Lorenz differential equations using Runge-Kutta 2cond grade sigma=10, r=28 and b=8/3 with initial conditions (x,y,z)=(0,1,0) this is the code i wrote, but it throws me an error saying overflow encountered in double_scalars , and I don't see what is wrong with the program from pylab import * def runge_4(r0,a,b,n,f1,f2,f3): def f(r,t): x=r[0] y=r[1] z=r[2] fx=f1(x,y,z,t) fy=f2(x,y,z,t) fz=f3(x,y,z,t) return array([fx,fy,fz],float) h=(b-a)/n

Lorenz attractor with Runge-Kutta python

时光怂恿深爱的人放手 提交于 2020-12-15 13:19:23
问题 Hello I have to program a python function to solve Lorenz differential equations using Runge-Kutta 2cond grade sigma=10, r=28 and b=8/3 with initial conditions (x,y,z)=(0,1,0) this is the code i wrote, but it throws me an error saying overflow encountered in double_scalars , and I don't see what is wrong with the program from pylab import * def runge_4(r0,a,b,n,f1,f2,f3): def f(r,t): x=r[0] y=r[1] z=r[2] fx=f1(x,y,z,t) fy=f2(x,y,z,t) fz=f3(x,y,z,t) return array([fx,fy,fz],float) h=(b-a)/n

Solving Lorenz equation using RK-4 in C++

陌路散爱 提交于 2020-06-27 06:31:11
问题 I wrote the code to solve Lorenz equations using RK-4 method in C++. I have to plot the attractor plot and I have some difficulty in solving the 3 first order coupled differential equation using RK-4 method. Here is my code: /* Solving 3 coupled first order differential equations using RK4 for the Lorentz system dxdt = sig*(y - x) {f} dydt = x*(rho - z) - y {g} dzdt = x*y - bet*z {k} */ #include<iostream> #include<cmath> #include<fstream> #include <iomanip> using namespace std; double sig =

Solving Lorenz equation using RK-4 in C++

…衆ロ難τιáo~ 提交于 2020-06-27 06:31:05
问题 I wrote the code to solve Lorenz equations using RK-4 method in C++. I have to plot the attractor plot and I have some difficulty in solving the 3 first order coupled differential equation using RK-4 method. Here is my code: /* Solving 3 coupled first order differential equations using RK4 for the Lorentz system dxdt = sig*(y - x) {f} dydt = x*(rho - z) - y {g} dzdt = x*y - bet*z {k} */ #include<iostream> #include<cmath> #include<fstream> #include <iomanip> using namespace std; double sig =

Lotka Volterra with Runge Kutta not desired precision

大兔子大兔子 提交于 2020-05-13 13:57:25
问题 Population over time (should be the same height at every peak I've programmed a code to simulate a mice and fox population using Runge-Kutta 4th order. But the result is not as wanted to be.. each peak should nearly be at same height I don't think that it is a problem of step size.. Do you have an idea? import matplotlib.pyplot as plt import numpy as np #function definition def mice(f_0, m_0): km = 2. #birthrate mice kmf = 0.02 #deathrate mice return km*m_0 - kmf*m_0*f_0 def fox(m_0, f_0): kf

Two_body_problem: scipy.integrate.RK45 gives broadcasting error and scipy.integrate.LSODA never enters the twoBody function

*爱你&永不变心* 提交于 2020-02-23 03:53:17
问题 I'm working on a trajectory calculator for the Two Body Problem, and I'm attempting to use Scipy's RK45 or LSODA to solve the ODE and return the trajectory. (Please suggest another method if you think there's a better/easier way to do this) I'm using the Spyder IDE with Anaconda. Scipy version 1.1.0 THE PROBLEMS: RK45: When using RK45, the first step seems to work. When stepping through the code in the debugger, twoBody() is entered, and works exactly as expected the first run through.