differential-equations

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 =

Python Euler Method implementation in Two Body Problem not working

夙愿已清 提交于 2020-06-22 03:54:10
问题 I am currently trying to get a two body problem to work, that I can then upgrade to more planets, but it is not working. It is outputting me impossible positions. Does anyone know what is causing that? This is the code I use: day = 60*60*24 # Constants G = 6.67408e-11 dt = 0.1*day au = 1.496e11 t = 0 class CelBody: def __init__(self, id, name, x0, y0, z0, vx0, vy0, vz0, mass, vector, ax0, ay0, az0, totalforcex, totalforcey, totalforcez): self.ax0 = ax0 self.ay0 = ay0 self.az0 = az0 self.ax =

differential equations BVP

三世轮回 提交于 2020-05-24 07:54:05
问题 #including the differential equations and parameters def model(x,dydx,p): s=p[0] #first parameter a=p[1] #second parameter dydx[0] = -2*(s+a)*y[0]+2*s*y[1]+s/2*y[2] dydx[1] = +2*(s+a)*y[1]-2*s*y[0]-s/2*y[2] dydx[2] = -(s+a)*y[2] return np.vstack(dydx[0],dydx[1],dydx[2]) # boundary conditions def bc(ya, yb,yc, p): s=p[0] a=p[1] I0=1 return np.array(([ya[0], yb[0],yc[0],a,s])) #x values x = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9]) y = np.zeros((3, x.size)) #p= np.zeros((3, d.size)) #y initial

SIR model using fsolve and Euler 3BDF

可紊 提交于 2020-04-30 05:44:46
问题 Hi i've been asked to solve SIR model using fsolve command in MATLAB, and Euler 3 point backward. I'm really confused on how to proceed, please help. This is what i have so far. I created a function for 3BDF scheme but i'm not sure how to proceed with fsolve and solve the system of nonlinear ODEs. The SIR model is shown as and 3BDF scheme is formulated as clc clear all gamma=1/7; beta=1/3; ode1= @(R,S,I) -(beta*I*S)/(S+I+R); ode2= @(R,S,I) (beta*I*S)/(S+I+R)-I*gamma; ode3= @(I) gamma*I; f(t,

Adapting initial-value problem to boundary-value problem using scipy.integrate.solve_bvp?

為{幸葍}努か 提交于 2020-04-18 06:32:15
问题 I would like to adapt an initial-value-problem (IVP) to a boundary-value-problem (BVP) using scipy.integrate.solve_bvp . A similar question was asked here, but I do not follow everything explained in the answer. The example below regarding the SIR model was taken from this website. Here, the initial condition y0 is taken to be the initial value of S , I , and R at time x0[0] . This system of ODEs is given by the function SIR below, which returns [dS/dt, dI/dt, dR/dt] over the interval from x