Tag Info

Hot answers tagged

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


6

The reason why you get a factor of 500 of I have explained in my comment. Let's replace your g with a better behaved function: mass = 100; width = 10^-2; g[x_] := mass/width HeavisideLambda[x/width] This is a triangular peak with area 100 and basewidth 0.01. Now let's impose the desired boundary conditions of $\partial u / \partial x =0$ at the ...


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


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


4

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


3

NIntegrate does each integral separately This has been observed before: NIntegrate piecewise vector function, Nested NIntegrate of vector function. It is also clear from the following BenchmarkPlot: int[n_] := Block[{shaxis}, shaxis = Table[1.0*i, {i, 1, n}]; NIntegrate[shaxis/(x^3 + 10), {x, 0, Infinity}, Method -> {"GlobalAdaptive", Method ...


3

The differential equation, its initial condition, and its boundary conditions are translationally invariant in space. Consequently, the solution must be independent of x and y. Indeed, solving the equations as given in the Question does give a spatially constant solution that oscillates in time. For instance, DensityPlot[Evaluate[Re[A[x, y, 10000]] /. ...


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


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


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


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_] := ...


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


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.


2

By using the output of ListContourPlot3D and the new Mathematica 10.0 feature DiscretizeGraphics, one can nicely generate a meshed contour region which is suitable for NIntegrate. We can show this for the above example for energy contours from 1.0 to 2.0 with a step width of 0.1: Monitor[Table[ e = ListInterpolation[data, {{-1, 1}, {-1, 1}, {-1, 1}}]; f ...


2

The reason for the error message is that C is a reserved system symbol. http://reference.wolfram.com/language/ref/C.html Since C has the attribute Protected, no further definitions can be made for it. http://reference.wolfram.com/language/ref/Protected.html


1

You are almost there. You only missed to create the list that you want to plot. Here are your definitions: (*parameters*) \[CapitalOmega]m = 1.0; \[CapitalOmega]\[CapitalLambda] = 0.0; \[CapitalOmega]k = 1 - \[CapitalOmega]m - \[CapitalOmega]\[CapitalLambda]; (*Integral with variable limits*) A[a_?NumericQ] := (5 \[CapitalOmega]m)/ 2 ...


1

y1 = 0; y2 = 1; n = 50; y = Range[y1,y2, (y2-y1)/(n-1.)]; f[x_, y_] := y Sin[x] If your function is Listable you can do this points = {y, NIntegrate[f[x, y], {x, 0, Pi}]} // Transpose; ListLinePlot[points] If your function is not Listable: points = Map[{#, NIntegrate[f[x, #], {x, 0, Pi}]} &, y] ListLinePlot[points]


1

I think this shows what the problem is. The ODE is inherently numerically unstable as any deviation from the exact solution goes to ±∞. asol = DSolve[{y''[x] == (x^2 - 1) y[x], y[0] == 1, y'[0] == p}, y[x], x]; Manipulate[ Plot[y[x] /. asol /. {{p -> 0}, {p -> 10^(-error)}, {p -> -10^(-error)}} // Evaluate, {x, 0, 7}, PlotRange -> 2], ...


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] *)


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 *)


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]



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