numerical-integration

Numerical Integral from 0 to infinity

*爱你&永不变心* 提交于 2019-12-23 02:14:21
问题 My aim is to calculate the numerical integral of a probability distribution function (PDF) of the distance of an electron from the nucleus of the hydrogen atom in C programming language. I have written a sample code however it fails to find the numerical value correctly due to the fact that I cannot increase the limit as much as its necessary in my opinion. I have also included the library but I cannot use the values stated in the following post as integral boundaries: min and max value of

Help with symplectic integrators

流过昼夜 提交于 2019-12-20 09:59:43
问题 I'm trying to develop a physics simulation and I want to implement a fourth-order symplectic integration method. The problem is that I must be getting the math wrong, since my simulation is not working at all when using the symplectic integrator (as compared to a fourth-order Runge-Kutta integrator that works reasonably well for the simulation). I've been googling this forever and all I can find are scientific articles on the subject. I tried to adapt the method used in the articles, but am

Understanding and implementing numerical integration with a quantile function in R

旧城冷巷雨未停 提交于 2019-12-20 04:58:14
问题 I need to calculate this integral below, using R: The q_theta(x) function I managed to do in R with quantile regression (package: quantreg ). matrix=structure(c(0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4, 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5, 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57,

Calculation of areas between two curves

▼魔方 西西 提交于 2019-12-19 10:45:14
问题 I have a code contain a curve and a line. I know how to fill the areas below and under the line but I need to calculate the areas values of each one. Here is the code: import matplotlib.pyplot as plt import numpy as np x = np.arange(0.0, 2, 0.01) y1 = np.sin(2*np.pi*x) y2 = 0*x fig, ax = plt.subplots(1, 1, sharex=True) ax.plot(x, y1, x, y2, color='black') ax.fill_between(x, y1, y2, where=y2 >= y1, facecolor='green', interpolate=True) ax.fill_between(x, y1, y2, where=y2 <= y1, facecolor='red',

Different intervals for Gauss-Legendre quadrature in numpy

折月煮酒 提交于 2019-12-19 07:21:46
问题 How can we use the NumPy package numpy.polynomial.legendre.leggauss over intervals other than [-1, 1] ? The following example compares scipy.integrate.quad to the Gauss-Legendre method over the interval [-1, 1] . import numpy as np from scipy import integrate # Define function and interval a = -1. b = 1. f = lambda x: np.cos(x) # Gauss-Legendre (default interval is [-1, 1]) deg = 6 x, w = np.polynomial.legendre.leggauss(deg) gauss = sum(w * f(x)) # For comparison quad, quad_err = integrate

Change a constant in ODE calculations under particular conditions with a flag

匆匆过客 提交于 2019-12-18 09:31:39
问题 I have an ODE for calculating how acidicity changes. Everything is working just fine, only I would like to change a constant whenever acidicity reaches a critical point. It is supposed to be some kind of irreversible effect I wish to simulate. My constants are coming from a structure file (c) I load once in the ODE function. [Time,Results] = ode15s(@(x, c) f1(x, c),[0 c.length],x0,options); The main problem I have here is not telling Matlab to change the constant but remember if it happened

R integrate: returns wrong solution (is using wrong quadrature points?)

不打扰是莪最后的温柔 提交于 2019-12-17 22:28:35
问题 I have a function in R which I am trying to integrate, but for some (extreme) values of the function parameters, integrate returns the incorrect solution. I believe the issue may be that integrate selects improper quadrature points for some of these extreme values, but first I will provide demonstrate the issue. The function I wish to integrate is the following. integrandFunc_F <- function(x, func_u, func_u_lowerBar, func_u_upperBar, func_mean_v, func_sigma_v, func_sigma_epsilon, func_sigma_y

Function with more arguments and integration

≯℡__Kan透↙ 提交于 2019-12-17 21:32:31
问题 I have I simple problem but I cannot find a solution anywhere. I have to integrate a function (for example using a Simpson's rule subroutine) but I am obliged to pass to my function more than one argument: one is the variable that I want to integrate later and another one is just a value coming from a different calculation which I cannot perform inside the function. The problem is that the Simpson subroutine only accept f(x) to perform the integral and not f(x,y). After Vladimir suggestions I

f2py, Python function that returns an array (vector-valued function)

末鹿安然 提交于 2019-12-17 20:49:24
问题 In the following Python I have five functions contained in the array returned by func which I have to integrate. The code calls an external Fortran module generated using f2py : import numpy as np from numpy import cos, sin , exp from trapzdv import trapzdv def func(x): return np.array([x**2, x**3, cos(x), sin(x), exp(x)]) if __name__ == '__main__': xs = np.linspace(0.,20.,100) ans = trapzdv(func,xs,5) print 'from Fortran:', ans print 'exact:', np.array([20**3/3., 20**4/4., sin(20.), -cos(20.

MATLAB: Is it possible to have two event values whilst using ode45?

感情迁移 提交于 2019-12-17 06:18:08
问题 I want two limitations to my ode45 calculation of a movement equation: position and time. I have already got the time event to work but I am not sure if and how I can add another event for limiting the position. EDIT: I also have many different particles coupled together in one ODE equation and need them to stop individually once they reach a 'roof' as they all travel at different speeds... would I be able to achieve this through events? I have an idea on how I would do this but its very