Not sure how it worked out, but changing the integration order from integral3(@(x,y,z) F(x,y,z),x1,x2,y1,y2,z1,z2) to integral3(@(z,x,y) F(x,y,z),z1,z2,x1,x2,y1,y2) solved the problem.

Yes, the logic is correct: mat will have zeros where the condition gamma2>gamma1 fails. You can test correctness yourself by using an example where you know the answer already. For instance, integration of f=gamma1*gamma2*s within [0,2] in each variable gives 8 (with paper and pencil), and if the condition gamma2>gamma1...

Your exp function isn't quite right -- it doesn't handle negative exponents correctly. Probably best just to use Math/pow. The other thing you could do is adjust your h value in volumeIntegral but to avoid stack issues, use recur (which gives you tail recursion), e.g. here's a slightly modified version:...

Your X-Y region of integration covers areas where f(x,y)-1.5 is negative, as well as positive. The intersection of your sphere with the line z=1.5 is a circle of radius sqrt(7/4) (using Pythagoras), so adjusting your limits appropriately, you get: library(pracma) f <- function(x, y) (sqrt(4 -x^2 - y^2) - 1.5...

c++,algorithm,integral,polynomials

A few pointers: Use std::vectors instead of pointers and new. (If you are new to C++, there are very few circumstances when you actually need to use new.) ComputeIntegral(double, double) will need to return a double, since it is obviously computing a definite integral. (The function you have at the...

Yes, sympy 0.7.6 is wrong in this case, and in some other such cases. Generally, I don't know any symbolic math package that I would trust to do calculus with piecewise defined functions. Note that although inner = Piecewise((0, (x>=y)|(x<0)), (a,True)) throws a TypeError at integration time, a logically equivalent...

c++,integral,numerical-integration

Unfortunately Simpson's rule can't be applied directly to multiple integrals. What you need to do is derive interpolant surfaces or hypersurfaces for double or triple integrals, respectively. For a double integral you end up evaluating the function on a grid of nine points instead of the three points you use...

Your procedure is correct. The problem is that Matlab doesn't know an explicit form for the primitive function. It produces the warning Warning: Explicit integral could not be found If you change x^3 to x, for example, there is an explicit integral (which can probably be found integrating by parts,...

objective-c,c,integral,riemann

int abs(int i) computes the absolute value of an integer. Therefore in abs(sqrt(6*s) - 3.141592) the floating point number sqrt(6*s) - 3.141592 is converted to an int first, which gives zero as soon as the absolute value of this number is less than one. You want to use fabs() instead....

python,matplotlib,plot,integral

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/pylab_examples/histogram_demo.html. Here they separate the output of...

It's because you didn't convert fact to a RealFrac before doing division: in tryForFact (fact:fs) (floor (fromIntegral x / fromIntegral fact)) You've said that fact = findAFact x, which has type Integral x => x, but you're using it in a division with /, so it thinks it needs to...

A Google search showed that it is possible that by 2011 there was no standard numerical option available. This is a library you could consider. Finally, how about using Monte Carlo?

c++,pointers,language-lawyer,integral,reinterpret-cast

No, that is not guaranteed by the standard. Quoting all parts of C++14 (n4140) [expr.reinterpret.cast] which concern pointerâ€“integer conversions, emphasis mine: 4 A pointer can be explicitly converted to any integral type large enough to hold it. The mapping function is implementation-defined. [ Note: It is intended to be unsurprising...

c,math,calculator,integral,calculus

y = 10.0 - (12.0 + (float)x) / 4.0; Followed by y = y+1; This makes sense else you have y uninitialized which leads to undefined behavior because the value of y is undeterminate. During declaration you can initialize y and use += operator. Like float y = 0;...

matlab,integral,best-fit-curve

The integral function requires its second and third arguments to be scalars. If you want to build the array dT of integrals over the limits contained in the array sT (or silkingTâ€”your reported error is not consistent with the provided code), use in the definition of function km: dT =...

For your 1st question, because * in Matlab represents matrix operator, so if not both sides of the operation are scalar, then both must have appropriate size, i.e m-by-n matrix * n-by-p matrix For 2nd question, you can define the function seperately, then use vertorizing instead of for-loop: J=q*mu*8*pi*sqrt(2)*m.^1.5/h^3*Farray(1,:)*integral(@(E)nrgInt(E,Farray(1,:),Barray(:)),0,Barray(:)); ...

haskell,warnings,show,ghci,integral

The compiler doesn't know which concrete implementation of Integral it should use. It guesses Integer would be ok. If you annotate e.g. calc, the warning will go away: main :: IO () main = interact (unlines . strout . (calc :: [Integer] -> [Integer]) . extinps . words) ...

There are multiple possible boundary conditions for splines, e.g.: second derivatives equals zero on the boundary given first derivatives on the boundary periodic conditions, i.e. same first and second derivatives on the boundary not-a-knot: take the outermost three points to specify the boundary conditions. It seems spline is using the...

python,python-2.x,sympy,integral

You may invoke the doit method: >>> f1.doit() f(t1) I believe SymPy is reluctant to perform these operations automatically since they may be arbitrarily expensive, and there is no universal system of predicting how expensive they will be. But maybe it would be wise to add some heuristics for integrals...

python,arrays,numpy,scipy,integral

The integral of exp(-x*x) is a scaled version of the error function, so you can use scipy.special.erf to compute the integral. Given scalars a and b, the integral of your function from a to b is 0.5*np.sqrt(np.pi)*(erf(b) - erf(a)). erf is a "ufunc", which means it handles array arguments. Given...

I solved with sympy: from sympy import * x, y = symbols("x y") f = (x ** 2 + y ** 2) res = integrate(f, (y, 20, x-2), (x, 22, 30)) Basically sympy.integrate is able to deal with multiple integrations, also with variable boundaries....

python,python-2.7,python-2.x,integral,data-fitting

You could, for instance, separately define the integrand function, def debye_integrand(x, n): return x**n/((np.exp(x) - 1)*(1 - np.exp(-x))) and then use scipy.integrate.quad to do this integration numerically, from scipy.integrate import quad def debye_func(p, T, r): # [...] the rest of your code from above here err_debye = r - rho0...