numerical-methods

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 =

How do I obtain the machine epsilon in R?

家住魔仙堡 提交于 2020-06-09 10:59:08
问题 Is there a constant that stores the machine epsilon in R? 回答1: Try .Machine$double.eps -- and .Machine which on my 32-bit Linux machine yields this: R> .Machine $double.eps [1] 2.220e-16 $double.neg.eps [1] 1.110e-16 $double.xmin [1] 2.225e-308 $double.xmax [1] 1.798e+308 $double.base [1] 2 $double.digits [1] 53 $double.rounding [1] 5 $double.guard [1] 0 $double.ulp.digits [1] -52 $double.neg.ulp.digits [1] -53 $double.exponent [1] 11 $double.min.exp [1] -1022 $double.max.exp [1] 1024

How do I obtain the machine epsilon in R?

限于喜欢 提交于 2020-06-09 10:58:07
问题 Is there a constant that stores the machine epsilon in R? 回答1: Try .Machine$double.eps -- and .Machine which on my 32-bit Linux machine yields this: R> .Machine $double.eps [1] 2.220e-16 $double.neg.eps [1] 1.110e-16 $double.xmin [1] 2.225e-308 $double.xmax [1] 1.798e+308 $double.base [1] 2 $double.digits [1] 53 $double.rounding [1] 5 $double.guard [1] 0 $double.ulp.digits [1] -52 $double.neg.ulp.digits [1] -53 $double.exponent [1] 11 $double.min.exp [1] -1022 $double.max.exp [1] 1024

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

Differentiate a 2d cubic spline in python

隐身守侯 提交于 2020-05-09 06:56:13
问题 I'm using interpolate.interp2d() to fit a 2-D spline over a function. How can I get the first derivative of the spline w.r.t. each of the dependent variables? Here is my code so far, Z are the descrete points on a mesh-grid that I have from scipy import interpolate YY, XX = np.meshgrid(Y, X) f = interpolate.interp2d(AA, XX, Z, kind='cubic') So, I need df/dx and df/dy. Note also that my Y-grid is not evenly spaced. I guess I can numerically differentiate Z and then fit a new spline, but it

How to reduce integration time for integration over 2D connected domains

寵の児 提交于 2020-05-07 03:53:10
问题 I need to compute many 2D integrations over domains that are simply connected (and convex most of the time). I'm using python function scipy.integrate.nquad to do this integration. However, the time required by this operation is significantly large compared to integration over a rectangular domain. Is there any faster implementation possible? Here is an example; I integrate a constant function first over a circular domain (using a constraint inside the function) and then on a rectangular

C Code Wavelet Transform and Explanation

有些话、适合烂在心里 提交于 2020-04-30 06:16:15
问题 I am trying to implement a wavelet transform in C and I have never done it before. I have read some about Wavelets, and understand the 'growing subspaces' idea, and how Mallat's one sided filter bank is essentially the same idea. However, I am stuck on how to actually implement Mallat's fast wavelet transform. This is what I understand so far: The high pass filter, h(t), gives you the detail coefficients. For a given scale j, it is a reflected, dilated, and normed version of the mother

C Code Wavelet Transform and Explanation

♀尐吖头ヾ 提交于 2020-04-30 06:15:06
问题 I am trying to implement a wavelet transform in C and I have never done it before. I have read some about Wavelets, and understand the 'growing subspaces' idea, and how Mallat's one sided filter bank is essentially the same idea. However, I am stuck on how to actually implement Mallat's fast wavelet transform. This is what I understand so far: The high pass filter, h(t), gives you the detail coefficients. For a given scale j, it is a reflected, dilated, and normed version of the mother