# Tag Info

0

I found two solution for this problem but one is time-consuming and the other is limited so I'm not quite satisfied. Solution 1 A higher WorkingPrecision will help: l = 10; nsol = NDSolve[{y''[x] == (x^2 - 1) y[x], y[0] == 1, y'[0] == 0}, y, {x, 0, l}, WorkingPrecision -> 50]; // AbsoluteTiming Plot[y[x] /. nsol, {x, 0, l}, PlotRange -> All] ...

5

To illustrate whats going on, your function is 0 at x=0, rises to a max and becomes essentially zero very quickly. With[{a = .9}, Plot[x Exp[-(a^2+.001^2) x^2], {x, 0, 3}]] Now look at the values NIntegrate computes: res = Reap[With[{a = .9}, NIntegrate[y = x Exp[-(a^2 + 0.001^2) x^2], {x, 0, 8000}, EvaluationMonitor :> Sow[{x, ...

3

Treat the maximum machine number as a singularity: ListPlot[Table[{a, NIntegrate[x Exp[-(a^2 + 0.001^2) x^2], {x, 0, 0.5 Log[\$MaxMachineNumber/(a^2 + 0.001^2)], 8000}]}, {a, 0.001, 1, 1/100}], Joined -> True Update [Forgive me, I actually have a job, and, while I could solve the problem quickly over breakfast, I could not compose a complete ...

0

A quick and dirty use of Parallelize gave me a 2.7x speed improvement on my machine (4-core CPU w/ hyperthreading). But since NIntegrate itself cant be parallelized, I used Map to do the trick ...

2

The code in the Question runs slowly, because it evaluates n^2 integrals. However, all the integrands are of the form Dc Exp[-Ax (x - a1)^2] Exp[-Ay (y - b1)^2] Exp[-Ax (x - a2)^2] Exp[-Ay (y - b2)^2]; This generic term can be integrated symbolically in several seconds Integrate[Laplacian[%, {x, y}], {x, -a, a}, {y, -b, b}] (* Dc (E^((-2*a^2 - a1^2 - ...

3

First note that, $$\oint_{E(\vec{x})=\epsilon}\frac{dS}{|\nabla E(\vec{x})|} =\oint_{E(\vec{x})=\epsilon}\frac{\nabla E(\vec{x})\cdot d\vec{S}}{|\nabla E(\vec{x})|^2} = \int_{E(\vec{x})\leq\epsilon} \nabla\cdot\left( \frac{\nabla E(\vec{x})}{|\nabla E(\vec{x})|^2}\right) dV$$ By now, the volume integral can be evaluated by Integrate[f ...

2

Trace[Integrate[ Integrate[ Integrate[ E^(-v1 - v2 - v3) (v1 + v2 + v3)/3, {v3, 2 v1 - 5/2 v2, v2}], {v2, 4 v1/7, 5 v1/7}], {v1, 0, Infinity}]] Check one line before the result. I think this is what you want.

1

Try this exponential derivative operator: expD[f_, x_] := Module[{x0}, Sum[SeriesCoefficient[f, {x, x0, i}], {i, 0, \[Infinity]}] /. {x0 -> x} ] Examples: expD[x^2, x] (* (1 + x)^2 *) expD[Sin[x], x] (* Sin[1 + x] *) expD[Exp[x], x] (* Exp[1 + x] *)

0

Please simplify your equation. There is no reason you should post code that includes the multiplication of two real numbers; instead substitute their product. Moreover, you have vastly too many parentheses. When you simplify the integral in this way and replace your non-syntactic condition with the proper If statement, the integral is easily solved: ...

2

Translating what you have: h[f_, t_] := t*Sinc[Pi f t]^2; t = 1.127*10^(-7); val = 10^6; NIntegrate[h[f, t], {f, (# - 0.5)*val, (# + 0.5)*val}] & /@ Range[20] But I think it is better that you integrate symbolically the sinc^2 function and just evaluate it for different limits. ref: comment. To do it symbolically Clear[h, f, t] h[f_, t_] := ...

4

Here's a workaround. I'm not sure why the variables s1[t], s2[t] are not reset in my first answer (see edit history). We can take care of things manually by making s1 and s2 numerical functions. Block[{ti = Log@100, tf = Log@(10^9), a0 = 3.05917*^7, b0 = 3.05242*^7, s1, s2, s10 = 1, s20 = 1}, s1[t_?NumericQ] := s10; s2[t_?NumericQ] := s20; {{sol}, ...

3

If I understood correctly, you are trying to solve Ω in terms of a and the result of the integral P. I'd do something like this. f[a_?NumericQ, P_?NumericQ] := Module[{}, h[x_]:= 1/(1 + a x^2); FindRoot[ NIntegrate[x/(h[x] Exp[x/(h[x]) Ω] - 1),{x, 0, Infinity}] == P, {Ω, 2}]] // Quiet (*Maybe you would like to change the initial guess*) ...

3

I am a slightly confused by the equation for Fl[w] as it has a M term in it. However, since you are evaluating it with l = zero, that term drops out so I will ignore it in this answer. First step I think is good for this problem is to set h equal to a list: h = {0, 0.00015583, 0.0006215, ..., 0.00015583}; You can then view it by using the ListPlot ...

1

func[t_, v_] := With[{s = Length[v]/2}, 2 Total@MapIndexed[#1 Cos[First@#2 t] &, Reverse[v[[1 ;; s - 1]]]] + v[[s + 1]]] Test: h = {2, 4, 10, 5, 12, 34, 12, 11}; Integrate[func[t, h]^2, {t, 0.234, 0.432}] yields: 305.526 Adjust as desired for non-even list length

1

h = {5, 7, 8, 15, 11, 17, 20, 20, 5, 3}; (*put your vector here*) n = Length[h] ;(*length of the vector, Even number*) F[x_] = h[[n/2 + 1]] + 2 Sum[h[[n/2 - l]] Cos[x l], {l, 1, n/2 - 1}]; NIntegrate[F[x]^2, {x, 0.234, 0.432}]

1

is this what you are looking for? h = {2, 4, 10, 5, 12, 34, 12, 11}; n = Length[h]; f[x_?NumericQ] := h[[n/2 + 1]] + 2 NSum[ h[[n/2 - i]] Cos[x*i], {i, 1, n/2 - 1}] NIntegrate[f[x]^2, {x, 0.234, 0.432}]

1

Something like this?: rect4[f_, a_, b_, n_] := With[{ex = Integrate[f[y], {y, a, b}], r = Range[0, n]}, With[{h = (b - a)/2.^r}, {r, #, {"/"}~Join~Ratios@#}\[Transpose] &@ Abs[ex - (b - a) Mean /@ f /@ Range[a, b - h, h]]]] MatrixForm@rect4[#^2 &, -1, 1, 6]

3

The integral over a spherical region is easily performed by Mathematica even analytically. Assuming f=1 and for brevity putting the center of the sphere at the origin: Timing@Integrate[1, {x, -r, +r}, {y, -Sqrt[r^2 - x^2], +Sqrt[ r^2 - x^2]}, {z, -Sqrt[r^2 - x^2 - y^2], +Sqrt[r^2 - x^2 - y^2]}] (*{0.218401, 4 Pi r^3 / 3}*) Assigning a numerical value to ...

3

For your example, I would simply do this: R = 2.3; {x0, y0, z0} = {1.2, 2.3, 3.4}; NIntegrate[1, {x, -R + x0, R + x0}, {y, y0 - Sqrt[R^2 - (x - x0)^2], y0 + Sqrt[R^2 - (x - x0)^2]}, {z, z0 - Sqrt[R^2 - (x - x0)^2 - (y - y0)^2], z0 + Sqrt[R^2 - (x - x0)^2 - (y - y0)^2]}]; For a general function func = Function[{x,y,z},body] and a set of boundaries ...

1

I believe it's a bug, integrating to Infinity yields the correct result of 1.: Integrate[f[x], {x, Exp[x0], Infinity}] (* 1. *) Also, I think it's also a part of the possible issues for definite integrals, listed in the Integrate: eq = Integrate[f[x], x]; (eq /. {x -> 10}) - (eq /. {x -> Exp[x0]}) (* 0.992038 *)

8

Using approximate numbers (e.g. ones with decimal points) can lead to issues with exact solvers such as Integrate. One way around, if the function can be integrated with symbolic parameters, is to use Block to block the numeric values from being substituted until after the integration is complete: Block[{x0, a, b}, Assuming[a > 0 && b > 0 ...

0

Adding "SymbolicProcessing" -> 0 (it's probably the "default setting" of Matlab, right?) and making use of parallelism gives me a 3X speedup on my dual-core old laptop: laxis = ParallelTable[1.0 i, {i, 1, 2046}]; Total[ParallelMap[ NIntegrate[#/(x^3 + 10), {x, 0, Infinity}, Method -> {"GlobalAdaptive", Method -> "GaussKronrodRule", ...

0

CenAng returns a real value not a vector. You can visualize dependency on t and m: Plot3D[CenAng[t, mu], {t, 0, Pi/2}, {mu, 1.01, 3}] ContourPlot[CenAng[t, mu], {t, 0, Pi/2}, {mu, 1.01, 3}, ContourLabels -> (Text[Framed[#3], {#1, #2}, Background -> White] &)]

2

In Mathematica 10 I can evaluate this directly, without any intermediate steps. With[{α1 = 1.4, α2 = 0.8, x0 = 8, y0 = 1}, Integrate[ Piecewise[{{Exp[-y x^α1], x <= x0}, {Exp[-x0^(α1 - α2) y x^α2], x > x0}}], {x, 0, Infinity}, {y, y0, Infinity}, PrincipalValue -> True]] (* ∞ *)

3

According to your statement, I think what you need is just 4th-order Runge-Kutta method, and a completely self-made implementation of 4th-order Runge-Kutta method isn't necessary, then the answer from J.M. has shown you the optimal direction: (* Unchanged part omitted. *) ClassicalRungeKuttaCoefficients[4, prec_] :=With[{amat = {{1/2}, {0, 1/2}, {0, 0, ...

Top 50 recent answers are included