Tag Info

Hot answers tagged

26

The only reason I am attempting to answer this is to perhaps get a Reversal badge. There you go... We will go slowly and this answer is the basis for what comes next. Let's start with two dimensions. You'll see why. We create a rectangular region: Needs["NDSolve`FEM`"] mesh = ToElementMesh[FullRegion[2], {{0, 5}, {0, 1}}, "MeshOrder" -> 1, ...


16

After a lengthy study (I'm using version 8) I conclude that there is a bug in Mathematica in the Integrate function when applied to a Sqrt integrand. Ok. let's go (some patience is required because of the long text) Let us define the functions corresponding to your integrals. Remark: because of the relation $1 + cos(2x) = 2 cos^2(x)$ the two forms of ...


12

In this second answer I give the cause for the mismatch in the integrals, show how to remove it, and make a suggestion to improve the function Integrate[]. Simplified restatement of the problem In order to focus on the core of the problem we consider the simpler integral $\int_0^1 \sqrt{\cos (2 π k r)+1} \, dr$. It has the square root and the cosine ...


9

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 ...


9

Update The problem is subtler than my first analysis revealed. There is indeed a problem with the variable et in NIntegrate not being properly blocked. Part of the problem has to do with the extra braces in firstFuncK which has the form {{f -> InterpolatingFunction[<>]}} Somehow that leads to an evaluation of et in the integrand f[et, k] /. ...


9

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


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 ...


7

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}, ...


6

There are two ways come to my mind to go. 1. Truncate the upper limits: Since OP has an exponential decay term like what it reads, truncating the integral limits at 2000000 should give a reasonably precise result: NIntegrate[( E^(-(x - 1000000)^2/(2*200000^2)) *E^(-(y - 1000000)^2/(2*200000^2)) *E^(-(z ...


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, ...


5

Below are a couple of ways to add to Silvia's two. First a couple of remarks. Using 1/10 instead of 0.1 in the specification of the region allows Mathematica to apply exact methods. This may help, but it can also add significantly to computation time sometimes. What is important is to realize that there is a difference and to become familiar with the ...


4

This volume between the regions can be obtained as follows: f[x_] := Pi^2 Sin[x] Cos[x]^3 g[x_] := 4 x^2 v1 = Integrate[Pi g[z]^2, {z, 0, Pi/4}] v2 = Integrate[Pi f[z]^2, {z, 0, Pi/4}] N[v2 - v1] yielding: [Pi]^6/320,(1/48 + (5 [Pi])/512) [Pi]^5, 12.7596 respectively. You can use a number of v10 capabilities to visualize region and approximate volume ...


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

Rahbar and Hashemizadeh's approach You could use the code provided by PlatoManiac in response to a similar question which implements the method from Rahbar and Hashemizadeh's paper A Computational Approach to the Fredholm Integral Equation of the Second Kind. NISolve.nb The Mathematica library includes code for Numerical Solution of One-Dimensional Linear ...


3

Timing under 20 seconds on my computer now. Ok, your original program took about 60 seconds on my computer meaning that my computer is faster. The dramatical gain of time is due to halfing the MaxRecursion option value. The plot still shows no visible difference. I replaced Pi-Symbol by Pi for increasing readability in forum. I tested some scenarios, and ...


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 ...


3

ftop = Pi^2 Sin[x] Cos[x]^3 fbtm = 4 x^2; Plot[{ftop, fbtm}, {x, 0, Pi/4}] Use Volume = Pi r^2 * h (cylinder volume) for top and bottom and take the difference (i.e remove volume of inner cylinder from outer) vtop = Pi Integrate[ftop^2, {x, 0, Pi/4}]; vbtm = Pi Integrate[fbtm^2, {x, 0, Pi/4}]; vtop - vbtm N[%] (* 12.7596 *) The area of the ...


2

Summarizing all of the comments: Clear[T] T[e_?NumericQ] := (1/Pi)*NIntegrate[ 1/Sqrt[Sin[ArcCos[-e]/2]^2 - Sin[\[Phi]/2]^2], {\[Phi], 0, ArcCos[e]/2}] Plot[ {Re[T[e]], Im[T[e]], Abs[T[e]]}, {e, -2, 2}, PlotRange -> All, WorkingPrecision -> 25, PlotLegends -> "Expressions", Frame -> True, Axes -> False] EDIT: With the ...


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: ...


1

Two small changes make this work in a much nicer way: First, the use of NDSolveValue instead of NDSolve gets rid of this rule replacement monkey business. {tini, tfin} = {-Log[100], 0}; firstFuncK = NDSolveValue[{D[f[t, k], t] + f[t, k]^2 + (1 - t)*f[t, k] == 3/2*(1 + k^2), f[tini, k] == 1}, f, {t, tini, tfin}, {k, 0.001, 10}] (* ...


1

If you were to have, for example, dt = .01; tbl = Table[{t, Exp[Cos[t]]}, {t, 0, 10, dt}]; (that is, your $f(t)$ corresponds to my tbl) then another way is Total @ MapThread[ Sin[2*Pi #1]^2 * #2 &, Thread @ tbl ] * dt But of course any technique can be easily used (trapezoidal or more sophisticated approaches).


1

Let's denote values {t, f(t)} as F, then interpolate this array with ListInterpolation. fx = ListInterpolation[F[[All, 2]], {F[[1, 1]], F[[-1, 1]]}] Now we may use Integrate with fx Integrate[Sin[2*Pi*t]*fx[t], {x, F[[1, 1]], F[[-1, 1]]}] As you see, it's not exactly what you want: the domain of integration is {F[[1, 1]], F[[-1, 1]]}.


1

This really has nothing to do with interpolating functions per se; it arises from the way Mathematica deals with functional expressions in general. Consider, f = #^2 &; g = -1 f; h = (-1 #)& @* f; hx[x_] = -1 f[x]; {f[2], g[2], h[2], hx[2]} {4, (-(#1^2 &))[2], -4, -4} Mathematica simply doesn't recognize g as a function, but h, which is ...



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