numerical-integration

Why is the integration not progressing with scipy.integrate.ode?

Why is the integration not progressing with scipy.integrate.ode? Question: I am integrating a function func in the complex domain using scipy.integrate.ode. I have assembled the following code structure: import numpy as np from scipy.integrate import ode def func(x, u, k): #f, g = u dfdx = k*x**2 dgdx = -x rhs_FD = [0]*2 rhs_FD[0] = …

Total answers: 1

Vectorized-oriented definition of functions (Python)

Vectorized-oriented definition of functions (Python) Question: I want to integrate a function using quadpy. I noticed that quadpy passes numpy arrays as arguments to the function. For example, if I define f = lambda x: x**2, then quadpy will integrate passing a vector like x = [0, 0.3, 0.7, 1]. The function I want to …

Total answers: 2

Why scipy.integrate shows has no "simpson" attribute?

Why scipy.integrate shows has no "simpson" attribute? Question: I have some python code which uses function scipy.integrate.simpson So for example I import scipy using import scipy.integrate as scp_int and then use it in following way: vol_r = scp_int.simpson(f_integrand_r,dx=_dx1,axis=0) I get this error vol_r = scp_int.simpson(f_integrand_r,dx=_dx1,axis=0) AttributeError: module ‘scipy.integrate’ has no attribute ‘simpson’` I have made …

Total answers: 1

How to integrate a function defined by an array

How to integrate a function defined by an array Question: I constructed and plotted a function defined by an array, according to the following code: # set parameters mean = np.array([0, 3]) sigma = np.array([1, .8]) weight = np.array([.4, .6]) factor = 4 points = 1000 # set limits for plot min_plot = (mean – …

Total answers: 1

How to use integrate.quad with an array

How to use integrate.quad with an array Question: I would like to use integrate.quad with an array but it returns me : "TypeError: only size-1 arrays can be converted to Python scalars" I understand that the first argument which is required must be a scalar. But the argument I want to use comes from a …

Total answers: 2

How to limit number of function calls in scipy.integrate.quad?

How to limit number of function calls in scipy.integrate.quad? Question: Scipy.integrate.quad() seems to make too many function calls in come cases. Here is a simple test to demonstrate: import numpy as np from scipy import integrate def intgnd(x): p = x + x**2 return p x0=-1 x1=1 epsrel=0.1 epsabs=0.1 I,err,info = integrate.quad(intgnd,x0,x1,full_output=1,epsabs=epsabs,epsrel=epsrel) print("{:.3f}, {:.3g}, {}, …

Total answers: 1

Why does Python RK23 Solver blow up and give unrealistic results?

Why does Python RK23 Solver blow up and give unrealistic results? Question: I am experimenting with RK45/RK23 solver from python scipy module. Using it to solve simple ODEs and it is not giving me the correct results. When I manually code for Runge Kutta 4th order it works perfectly so does the odeint solver in …

Total answers: 1

Laplace transform using numerical integration in Python has very poor precision

Laplace transform using numerical integration in Python has very poor precision Question: I have written a function to compute the Laplace transform of a function using scipy.integrate.quad. It is not a very sophisticated function and currently performs poorly on the probability density function of an Erlang distribution. I have included all my work below. I …

Total answers: 1

Scipy integrate: is solve_ivp "always worse" than odeint?

Scipy integrate: is solve_ivp "always worse" than odeint? Question: Analytical solution for an example ODE I was testing the difference between these methods by solving the following initial value problem: y’=2*y-t You can solve this analytically by considering that y(t) is a linear combination of a homogeneous solution y_h(t)=c1*exp(2t) and a particular solution y_p(t)=t/2+1/4. The …

Total answers: 1