numerical-integration

Internal working of scipy.integrate.ode

放肆的年华 提交于 2019-12-07 13:36:02
问题 I'm using scipy.integrate.ode and would like to know, what happens internally when I get the message UserWarning: zvode: Excess work done on this call. (Perhaps wrong MF.) 'Unexpected istate=%s' % istate)) This appears when I call ode.integrate(t1) for too big t1 , so I'm forced to use a for -loop and incrementally integrate my equation, what lowers the speed since the solver can not use adaptive step size very effectively. I already tried different methods and setting for the integrator. The

Solving a delay differential equation (DDE) system constrained to give nonnegative solutions

若如初见. 提交于 2019-12-07 04:23:18
问题 In MATLAB, ode45 has a parameter called NonNegative which constrains the solutions to be nonnegative. They even wrote a paper about how this method works and how it's not something as stupid as just setting y_i to 0 whenever it becomes negative, as that won't generally work. Now, MATLAB also has dde23 for solving delay differential equations, but there is no equivalent NonNegative parameter for this integrator. Unfortunately, I am tasked with adding a delay to an existing ODE system which is

performance of adaptIntegrate vs. integrate

℡╲_俬逩灬. 提交于 2019-12-07 02:01:26
问题 I'd like to perform a numerical integration in one dimension , where the integrand is vector-valued . integrate() only allows scalar integrands, thus I would need to call it several times. The cubature package seems well suited, but it seems to perform quite poorly for 1D integrals. Consider the following example (scalar-valued integrand and 1D integration), library(cubature) integrand <- function(x, a=0.01) exp(-x^2/a^2)*cos(x) Nmax <- 1e3 tolerance <- 1e-4 # using cubature's adaptIntegrate

Integration of Multivariate Normal Distribution in Python

故事扮演 提交于 2019-12-06 06:39:46
问题 I am trying to integrate over a multivariate distribution in python. To test it, I built this toy example with a bivariate normal distribution. I use nquad() in order to extend it to more than two variables later on. Here is the code: import numpy as np from scipy import integrate from scipy.stats import multivariate_normal def integrand(x0, x1, mean, cov): return multivariate_normal.pdf([x0, x1], mean=mean, cov=cov) mean = np.array([100, 100]) cov = np.array([[20, 0], [0, 20]]) res, err =

how to use scipy.integrate to get the volume of a truncated sphere?

无人久伴 提交于 2019-12-06 04:13:19
问题 I'm struggling with using scipy.integrate, I used tplquad, but how can I used integrate to get the volume of (truncated)sphere? Thanks import scipy from scipy.integrate import quad, dblquad, tplquad from math import* from numpy import * R = 0.025235 #radius theta0 = acos(0.023895) #the angle from the edge of truncated plane to the center of sphere def f_1(phi,theta,r): return r**2*sin(theta)*phi**0 Volume = tplquad(f_1, 0.0,R, lambda y: theta0, lambda y: pi, lambda y,z: 0.0,lambda y,z: 2*pi)

How to divide time interval into parts of varying length?

二次信任 提交于 2019-12-05 19:46:14
I have a time interval from 0 to t . I want to divide this interval into a cumulative sequence in a cycle of 2.25, 2.25 and 1.5, in the following manner: input: start = 0 stop = 19 output: sequence = [0, 2.25, 4.5, 6, 8.25, 10.5, 12, 14.25, 16.5, 18, 19] How can I do this in Python? The idea is to divide a time period into cycles of 6 hours, each cycle consisting of three sequential operations that last 2.25 h, 2.25 h and 1.5 h respectively. Or is there an alternative to using 'milestones' for this purpose? You could use a generator: def interval(start, stop): cur = start yield cur # return

Internal working of scipy.integrate.ode

非 Y 不嫁゛ 提交于 2019-12-05 19:32:08
I'm using scipy.integrate.ode and would like to know, what happens internally when I get the message UserWarning: zvode: Excess work done on this call. (Perhaps wrong MF.) 'Unexpected istate=%s' % istate)) This appears when I call ode.integrate(t1) for too big t1 , so I'm forced to use a for -loop and incrementally integrate my equation, what lowers the speed since the solver can not use adaptive step size very effectively. I already tried different methods and setting for the integrator. The maximal number of steps nsteps=100000 is very big already but with this setting I still can't

Looking for Python package for numerical integration over a tessellated domain

烂漫一生 提交于 2019-12-05 05:37:45
I was wondering if anyone knew of a numpy/scipy based python package to numerically integrate a complicated numerical function over a tessellated domain (in my specific case, a 2D domain bounded by a voronoi cell)? In the past I used a couple of packages off of the matlab file exchange, but would like to stay within my current python workflow if possible. The matlab routines were http://www.mathworks.com/matlabcentral/fileexchange/9435-n-dimensional-simplex-quadrature for the quadrature and mesh generation using: http://www.mathworks.com/matlabcentral/fileexchange/25555-mesh2d-automatic-mesh

How to overcome singularities in numerical integration (in Matlab or Mathematica)

核能气质少年 提交于 2019-12-05 04:24:19
I want to numerically integrate the following: where and a , b and β are constants which for simplicity, can all be set to 1 . Neither Matlab using dblquad , nor Mathematica using NIntegrate can deal with the singularity created by the denominator. Since it's a double integral, I can't specify where the singularity is in Mathematica. I'm sure that it is not infinite since this integral is based in perturbation theory and without the has been found before (just not by me so I don't know how it's done). Any ideas? (1) It would be helpful if you provide the explicit code you use. That way others

Integration of Multivariate Normal Distribution in Python

你离开我真会死。 提交于 2019-12-04 13:44:44
I am trying to integrate over a multivariate distribution in python. To test it, I built this toy example with a bivariate normal distribution. I use nquad() in order to extend it to more than two variables later on. Here is the code: import numpy as np from scipy import integrate from scipy.stats import multivariate_normal def integrand(x0, x1, mean, cov): return multivariate_normal.pdf([x0, x1], mean=mean, cov=cov) mean = np.array([100, 100]) cov = np.array([[20, 0], [0, 20]]) res, err = integrate.nquad(integrand, [[-np.inf, np.inf], [-np.inf, np.inf]], args=(mean, cov)) print(res) The