Tag Info

Hot answers tagged

8

There is a useful attribute, NHoldFirst whose purpose is to protect the function from exactly that. So setting: SetAttributes[a, NHoldFirst]; and then evaluating the integral works the way you want: Integrate[(a[1] + x)^2, {x, 1., 2.}] (*2.33333 + 3. a[1] + 1. a[1]^2*) The relevant example from the documentation cites "indexed" functions that are ...


8

Update Almost ten times faster again, or about 90 times faster than the OP's way (0.069 sec v. 5.46 sec): For the second integral, we can find its derivative with respect to x and then integrate with NDSolve. The derivative of the integral has two components, one from differentiating under the integral sign dxdz1 and one from plugging in the limit of ...


6

The explanation was already delivered by Mr.Wizard, but I would like to add that there is a similar capability to the Indexed approach already built in to NDSolve or NDSolveValue. So we can leverage NDSolve instead of NIntegrate as follows: foo[x_?NumericQ] := {x^2, x^3}; NDSolveValue[{y'[x] == foo[x], y[0] == {0, 0}}, y, {x, 0, 1}][1] (* ==> {0.333333, ...


6

The sum of the squares should be less than or equal to r^2 rather than r. d = 10; r = 1000; F = Piecewise[{{1, Sum[x[i]^2, {i, d}] <= r^2}}, 0]; NIntegrate[F, {x[1], -1000, 1000}, {x[2], -1000, 1000}, {x[3], -1000, 1000}, {x[4], -1000, 1000}, {x[5], -1000, 1000}, {x[6], -1000, 1000}, {x[7], -1000, 1000}, {x[8], -1000, 1000}, {x[9], -1000, 1000}, ...


5

In Mathematica 10, this computation may be made as follows: Clear @ r volSphere9[r_] = RegionMeasure[Ball[ConstantArray[0, 10], r]] (π^5 r^10)/120 volSphere9[1000.] 2.55016*10^30


4

This seems like a bug, or at least a "glitch" in NIntegrate. I believe that it expects the evaluated structure of the integrand to match when given symbolic and numeric input. I imagine that it looks at the structure of the output of foo[x] and then sets up the rest of the computation based on that; when it then get a List output from e.g. foo[0] it fails ...


4

Put assumptions in: Clear[a, c] Integrate[ q^2 ((4 (c π))/((a q^2 - c) (c + a q^2))), {q, 0, ∞}, Assumptions -> {a, c} ∈ Reals] (* ConditionalExpression[(Sqrt[c] π^2)/a^(3/2), (a > 0 && c > 0) || (a < 0 && c < 0)] *)


4

The exact analytic soultion 1. Introduction The problem was still intriguing me with the result of a further study which I present in the following, for clarity as another solution. I have chosen to write the formulas in the more theoretical text in traditonal form. Abstract We calculate here the explcit analytic solution for the integral $f(k,R)=\int ...


3

As it is (unspecified k[t], A) NDSolve will not work. However the equations can be handled analytically. After a simple manipulation you can decouple them and get : rawx[t_] = x[t] /. DSolve[{k[t] x'''[t] - k'[t] x''[t] == -k[t]^3 x'[t]}, x[t], t] rawy[t_] = y[t] /. First@DSolve[{D[#, {t, 2}]/k[t] == y'[t]}, y[t], t] & /@ rawx[t] Now you can check ...


1

First, I did not get same result as your answer. I got numerical values in all terms. int = Integrate[(a[1] + x)^2, {x, 1., b}] MMA 9: (* -0.333333 + 0.333333 b^3 - 1. a[1.] + 1. b^2 a[1.] - 1. a[1.]^2 + 1. b a[1.]^2 + 5.55112*10^-17 a[1.]^3 *) MMA 10: (*-0.333333 (1. + a[1.])^3 + 0.333333 (b + a[1.])^3*) (Note: if you expand result from ...


1

Just to add a couple of more observations to Nasser's. Case 6 As Daniel Lichtblau hints at in a comment, if we use an exact 37/10 in place of the approximate 3.7, we get an exact result with a zero imaginary component: Integrate[PDF[NormalDistribution[14, 37/10], x], {x, 15, Infinity}] N@% (* 1/2 Erfc[(5 Sqrt[2])/37] 0.393476 *) Case 7 Such a small ...


1

I'd argue you should reformulate your function to avoid the issue -- however if a straightforward quadrature scheme will work for you (ie. you don't need adaptive schemes etc ) you can do a direct evaluation: Simpsons rule for example: foo[x_?NumericQ] := ({x^2, x^3}); np = 99;(*assumed odd for simpsons rule*) a = 0; b = 1; wt = (b - a)/(3 (np - 1)) ...


1

The Heaviside functions are essentially piecewise functions, and NIntegrate knows how to handle Piecewise functions but not Heaviside functions. In particular, it will analyze the domain of Piecewise functions and adjust its sampling accordingly. Here are two rules for conversion, ignoring boundary points which won't affect the integral anyway: ...



Only top voted, non community-wiki answers of a minimum length are eligible