integral

Nested integral within integral2 in matlab

爱⌒轻易说出口 提交于 2019-12-06 20:25:21
I'm attempting to take the double integral (using integral2) of a function that is defined by an integral. http://i.imgur.com/gIUsLSw.jpg Here is what I am currently attempting: t=linspace(0,1,50); fun_1= @(v) exp(.071*v) fun = @(x,y) exp(0.14*0.00607*integral(@(u)fun_1(u),0,x)).*exp(-(x-y).^2).*exp(0.14*0.00607*integral(@(u)fun_1(u),0,x)); for i=2:length(t) for j=i:length(t) A(i,j)=integral2(fun,t(i-1),t(i),t(j-1),t(j)); end end I'm receiving the error Error using integral (line 86) A and B must be floating point scalars. Can anyone provide any information on how to fix this problem. Here you

scipy.integrate.quad on arrays of limits

筅森魡賤 提交于 2019-12-06 12:48:52
quad from scipy.integrate needs the arguments func, a, b. Where func is a function to integrate and a and b is the lower and upper integration limits, respectively. a and b has to be numbers. I have a situation where I need to evaluate the integral of a function for hundreds of thousands of different a, b and sum the results. This takes a long time to loop through. I tried to just give quad arrays for a and b, hoping quad would return the corresponding array, but that didn't work. Here is a code illustrating what I'm trying to do, with both the Python loop that works, but is very slow, and my

Using scipy.quad with iε trick: Bad results

眉间皱痕 提交于 2019-12-06 07:35:48
In order to circumvent the cauchy principle value, I tried to integrate an integral using a small shift iε into the complex plane to evade the pole. However, as can be inferred from the figure below, the result is pretty bad. The code for this result is shown below. Do you have ideas how to improve this method? Why is it not working? I already tried changing ε or the limit in the integral. Edit: I included the method "cauchy" with the principle value, which seems not to work at all. import matplotlib.pyplot as plt from scipy.integrate import quad import numpy as np def cquad(func, a, b, *

efficient way of performing integral on an image

╄→гoц情女王★ 提交于 2019-12-06 06:20:40
I have a 2D array (typical size about 400x100) as shown (it looks like a trapezium because elements in the lower right are nan). For each element in the array, I want to perform a numerical integral along the column for several elements (of the order of ~10 elements). In physics language think of the colour as the magnitude of the force, and I want to find the work done by calculating th integral of Fdz. I can use a double for-loop and use trap to do the job, but are there other more efficient ways (probably mkaing use of arrays and vectorization) to do it in Matlab or python? My ultimate goal

Calculate area of cross section for varying height

十年热恋 提交于 2019-12-06 05:47:54
I'm trying to figure out how to calculate the area of a river cross section. For the cross section I have the depth at every 25 cm over the 5 m wide river. x_profile <- seq(0, 500, 25) y_profile = c(50, 73, 64, 59, 60, 64, 82, 78, 79, 76, 72, 68, 63, 65, 62, 61, 56, 50, 44, 39, 25) If anyone have some suggestions of how this could be done in r it's highly appreciated. We can use the sf package to create a polygon showing the cross-section and then calculate the area. Notice that to create a polygon, it is necessary to provide three more points as c(0, 0) , c(500, 0) , and c(0, 0) when creating

Different integration results using Monte Carlo vs scipy.integrate.nquad

梦想的初衷 提交于 2019-12-05 19:43:54
The MWE below shows two ways of integrating the same 2D kernel density estimate, obtained for this data using the stats.gaussian_kde() function. The integration is performed for all (x, y) below the threshold point (x1, y1) , which defines the upper integration limits (lower integration limits are -infinity ; see MWE). The int1 function uses simple a Monte Carlo approach. The int2 function uses the scipy.integrate.nquad function. The issue is that int1 (ie: the Monte Carlo method) gives systematically larger values for the integral than int2 . I don't know why this happens. Here's an example

How to compute integration of a function in apache commons math3 library?

大兔子大兔子 提交于 2019-12-05 17:43:38
I am trying to integrate a very simple function. integral(x.dx). Instead of getting an answer of 1, I am getting an answer as 0, or 0.5 when I include limits from 0 to 1. Is there something I misunderstand about the implementation of the integration in apache commons library? import org.apache.commons.math3.analysis.integration.*; import org.apache.commons.math3.analysis.polynomials.*; public static void main(String args[]) { SimpsonIntegrator simpson = new SimpsonIntegrator(); TrapezoidIntegrator trapezoid = new TrapezoidIntegrator(); double[] vector = new double[2]; vector[0] = 0; vector[1]

Integrate histogram in python?

喜欢而已 提交于 2019-12-05 16:59:38
Is there a simple command in matplotlib that let's me take the integral of histogram over a certain range? If I plot a histogram with: fig = plt.hist(x, bins) Then, is there a command like fig.integral(bin1, bin2)? That will return the integral of the histogram from bin1 to bin2? First, remember that the integral is just the total area underneath the curve. In the case of a histogram, the integral (in pseudo-python) is sum([bin_width[i] * bin_height[i] for i in bin_indexes_to_integrate]) . As a reference, see this example of using a histogram in matplotlib: http://matplotlib.org/1.2.1/examples

Converting hard integral to lambda function with lambdify

不羁的心 提交于 2019-12-05 15:51:25
I would like to lambdify the function Integral(t**t,(t,0,x)) . It works, but my new function, which was returned by lambdify , doesn't return a number but only sympy.integrals.integrals.Integral class. But I don't want that, I want it to return a float number. Here is my code: import sympy as sp import numpy as np f = sp.lambdify(x,sp.integrate(t**t,(t,0,x))) print(f(2)) #return Integral(t**t, (t, 0, 2)) #but i want 2.83387674524687 lambdify doesn't support scipy.integrate.quad directly yet , but it's not difficult to add the appropiate definition. One simply needs to tell lambdify how to

Why is numeric_limits<int>::max() > numeric_limits<int>::infinity()?

喜夏-厌秋 提交于 2019-12-04 22:22:15
I was reading Setting an int to Infinity in C++ . I understand that when one needs true infinity, one is supposed to use numeric_limits<float>::infinity() ; I guess the rationale behind it is that usually integral types have no values designated for representing special states like NaN , Inf , etc. like IEEE 754 floats do (again C++ doesn't mandate neither - int & float used are left to the implementation); but still it's misleading that max > infinity for a given type. I'm trying to understand the rationale behind this call in the standard. If having infinity doesn't make sense for a type,