runge-kutta

Implementation of Runge Kutta Fourth Order in c++ [closed]

爷,独闯天下 提交于 2019-12-14 03:31:56
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . So I should start by saying that this is my first attempt a executable script, and my first ever c++ script. Bearing this in my mind my problem is as follows. I'm attempting to create a script which shall integrate projectile motion with the use of the Fourth Order Runge Kutta method. Currently my script is

Integrating differential equations of motion for orbit in Runge Kutta in C

守給你的承諾、 提交于 2019-12-12 03:48:45
问题 I'm attempting to integrate the differential equations for planetary orbit using fourth order runge-kutta in C. The first equation that I attempted to integrate was for the position, dr/dt = sqrt((2/mu)*(E-(k/r)) - pow(l, 2)/(pow(mu, 2)*pow(r, 2))). The program compiles correctly but keeps on returning nan, I'm fairly new to C so I'm wondering why that could be. The source code that I'm using is the following: double rk4 ( double t0, double u0, double dt, double f ( double t, double u ) ) { /

Runge Kutta 4 and pendulum simulation in python

放肆的年华 提交于 2019-12-11 07:49:15
问题 I am trying to make a python program which plot pendulum swings using runge kutta 4. The equation I have is angular accelartion = -(m*g*r/I) * np.sin(y) . Please find my code. I am quite new to python. import numpy as np import matplotlib.pyplot as plt m = 3.0 g = 9.8 r = 2.0 I = 12.0 h = 0.0025 l=2.0 cycle = 10.0 t = np.arange(0, cycle, h) n = (int)((cycle)/h) initial_angle = 90.0 y=np.zeros(n) v=np.zeros(n) def accel(theta): return -(m*g*r/I)*np.sin(theta) y[0] = np.radians(initial_angle) v

Solving ODEs in NetLogo, Eulers vs R-K vs R solver

杀马特。学长 韩版系。学妹 提交于 2019-12-08 13:33:32
In my model each agent solves a system of ODEs at each tick. I have employed Eulers method (similar to the systems dynamics modeler in NetLogo) to solve these first order ODEs. However, for a stable solution, I am forced to use a very small time step (dt), which means the simulation proceeds very slowly with this method. I´m curious if anyone has advice on a method to solve the ODEs more quickly? I am considering implementing Runge-Kutta (with a larger time step?) as was done here ( http://academic.evergreen.edu/m/mcavityd/netlogo/Bouncing_Ball.html ). I would also consider using the R

C++ numerical integrators to solve systems of ode's

别来无恙 提交于 2019-12-08 13:31:16
问题 I recently started using C++ and I just created a class that allows the integration of a user-defined system of ode's. It uses two different integrators in order to compare its performance. Here is the general layout of the code: class integrators { private: double ti; // initial time double *xi; // initial solution double tf; // end time double dt; // time step int n; // number of ode's public: // Function prototypes double f(double, double *, double *); // function to integrate double rk4

Solving ODEs in NetLogo, Eulers vs R-K vs R solver

非 Y 不嫁゛ 提交于 2019-12-08 08:59:20
问题 In my model each agent solves a system of ODEs at each tick. I have employed Eulers method (similar to the systems dynamics modeler in NetLogo) to solve these first order ODEs. However, for a stable solution, I am forced to use a very small time step (dt), which means the simulation proceeds very slowly with this method. I´m curious if anyone has advice on a method to solve the ODEs more quickly? I am considering implementing Runge-Kutta (with a larger time step?) as was done here (http:/

Scanf_s warning? Skips User Inputs (topics: Runge-Kutta, Epidemic Simulation)

感情迁移 提交于 2019-12-04 04:52:25
问题 This is my first post and I have to admit, I am terrible at programming. I am that guy in the class that works his tail off, but can never seem to grasp programming as well as the rest of my classmates. So please be nice, I will try to explain my problem below. I have the following code (comments removed), but when I run it I get a warning similar to the one listed below. Also, when I run the program, the first user inputted value is allowed, but then all of the sudden, it jumps to the end of

Integration of orbits with solar system gravity fields from Skyfield - speed issues

落花浮王杯 提交于 2019-12-03 16:42:05
In the time tests shown below, I found that Skyfield takes several hundred microseconds up to a millisecond to return obj.at(jd).position.km for a single time value in jd , but the incremental cost for longer JulianDate objects (a list of points in time) is only about one microsecond per point. I see similar speeds using Jplephem and with two different ephemerides. My question here is: if I want to random-access points in time, for example as a slave to an external Runge-Kutta routine which uses its own variable stepsize, is there a way I can do this faster within python (without having to

Solve a system of three equations with Runge Kutta 4: Matlab

老子叫甜甜 提交于 2019-12-02 00:47:46
I want to solve a system of THREE differential equations with the Runge Kutta 4 method in Matlab ( Ode45 is not permitted). After a long time spent looking, all I have been able to find online are either unintelligible examples or general explanations that do not include examples at all. I would like a concrete example on how to implement my solution properly, or the solution to a comparable problem which I can build on. I have come quite far; my current code spits out a matrix with 2 correct decimals on most of the components , which I am quite happy with. However, when the step-size is

Scanf_s warning? Skips User Inputs (topics: Runge-Kutta, Epidemic Simulation)

狂风中的少年 提交于 2019-12-01 23:22:44
This is my first post and I have to admit, I am terrible at programming. I am that guy in the class that works his tail off, but can never seem to grasp programming as well as the rest of my classmates. So please be nice, I will try to explain my problem below. I have the following code (comments removed), but when I run it I get a warning similar to the one listed below. Also, when I run the program, the first user inputted value is allowed, but then all of the sudden, it jumps to the end of the program, not allowing me to input the values for the other variables (e.g. the variable "beta"). I