Tag Info

New answers tagged

2

We can see why this happens looking at the indefinte integral: indef = Integrate[Exp[-2/3 Log[1 + x^3]], x] analytic expression involving Hypergeometric2F1 This expression changes character and picks up an imaginary component right at 1: Plot[{ Re[indef ], Im[indef ]}, {x, 0, 1.3}] Evaluating the definite integral using the left value at 1 we ...


4

You're getting an imaginary number because you're using integers. Integrate[Exp[-2./3. Log[1. + x^3.]], {x, 0, 1}] (* 0.883319 *) Also: Integrate[Exp[-a Log[1 + x^3]], {x, 0, 1}] (* Hypergeometric2F1[1/3, a, 4/3, -1] *) You can then replace a by $2/3$: Hypergeometric2F1[1/3, a, 4/3, -1] /. a -> 2/3 $\frac{\Gamma \left(\frac{1}{3}\right) \Gamma ...


1

A = {{0.1, 0}, {0, 0.1}}; B = {{2, 3}, {-3, 1}}; c = {{0.2, 0.6}, {0.2, 0}}; d = {2, 3}; e = {1, 0}; i = {{1, 0}, {0, 1}}; g[11] = {0, 0}; g[t_] := A.S[t+1].Inverse[i-B.S[t+1]].(B.g[t+1]-d)+A.g[t+1]+e; p[11] = {0, 0}; p[t_] := S[t].X[t] - g[t]; S[11] = {{0, 0}, {0, 0}}; S[t_] := c + A.S[t + 1].Inverse[i - B*S[t + 1]].A ; X[1] = {1, 0}; X[t_] := Inverse[i - ...


5

The interpolation overshoots the next point and reverses direction. ParametricPlot[{line[[1]][tt], line[[2]][tt]}, {tt, 0.2, 0.3}, Epilog -> {Point[points[[All, 1 ;; 2]]]}] You can reduce the interpolation order to 1 or use a centripetal parametrization parametrizeCurve from J.M.'s answer. parametrizeCurve[pts_List, a : (_?NumericQ) : 1/2] := ...


2

If a highly accurate solution is desired, I would follow kguler's comment; otherwise, here is a variation on Alexei Boulbitch's approach: sol = NDSolveValue[{y'[x] == 3 x^2, y[0] == 0, WhenEvent[y[x] == 3, "StopIntegration"]}, y, {x, 0, 3}]; sol["Domain"][[1, -1]] (* 1.44225 *) Or somewhat more directly: Catch @ NDSolve[{y'[x] == 3 x^2, y[0] == 0, ...


1

It seems to me that infinitely many, semi periodic singularities makes for a very difficult integral. If you could find a substitution that would tame all the singularities at once, you could probably succeed in truly taming this integral. I agree with the OP that each singularity is integrable, but one has also to wonder whether the sum of the infinitely ...


2

To elaborate on my Comment (and assuming uniform spacing of the data), consider the toy problem in 1-D: f = Table[Sin[2 Pi ( i - .5)/10], {i, 10}] Generating an InterpolatingFunction and then using NIntegrate yields: g = Interpolation[f] NIntegrate[g[x], {x, 1, 10}] (* 3.3306690738754696*^-16 *) Simply forming the Total yields the same result to ...


3

Nasser gave a fine and simple enough approach. I will propose a different, not that it is better, but just to give another view. So, if in general you have an integral y[t]==Integrate[f[x],{x,0,t}], it is equivalent to the differential equation: y'[t]=f[t] with the initial condition y[0]==0. You might solve it numerically and then find the solution of the ...


1

You can't do numerical integration with upper limit being symbol. Just use Integrate instead ClearAll[t, x, x1, x2, nv] nv[x1_, x2_] := Integrate[3 x^2, {x, x1, x2}] FindRoot[nv[0, t] == 3, {t, .001}]


1

I found that setting "LocationMethod" -> "LinearInterpolation" solves the problem by avoiding using a root-finding method to locate the event. It will also be a little faster, and since your motion is constant speed you will not lose any precision. (The hint was that the location always failed around t = 30, regardless of initial speed or position.) ...


3

This seems to work. However, expect some issues when the trajectory gets almost tangent to the inner circle. mf1[{x_, y_}] := x^2 + y^2 - (1/2)^2 mf2[{x_, y_}] := x^2 + y^2 - 1 sol = NDSolve[{ x'[t] == vx[t], y'[t] == vy[t], WhenEvent[ mf1[{x[t], y[t]}] mf2[{x[t], y[t]}] == 0, {vy[t] -> -9/10 vy[t], vx[t] -> -vx[t]}, ...


1

If you are happy with the findings so far, and just need help on dynamically creating the exclusions, you might want to proceed with the following index-generation code: DeleteDuplicates@{#1,#2,Sequence@@Range[Ceiling[#2,2\[Pi]],Floor[#3,2\[Pi]],2\[Pi]],#3}& which can be called with the variable and its lower and upper bounds like so, e.g.: ...


1

You may try to fit a boundary condition, although it won't give you hints about the inner workings: sol = u /. NDSolve[{ D[u[t, x], t] == D[u[t, x], x, x], u[0, x] == Exp[-x^2], Derivative[0, 1][u][t, -1] == 2/E}, u, {t, 0, 2}, {x, -1, 1}][[1]] n = 30; coefs = Table[c[i], {i, n}]; solMy = u /. ...


1

Works for me: gam1 = 2; gam2 = 1 - 2 I; ℛ = Polygon[{{0, 0}, {Re[gam2], Im[gam2]}, {gam1 + Re[gam2], Im[gam2]}, {gam1, 0}}]; NIntegrate[x^2*y^2, {x, y} ∈ ℛ] (* 18.3111 *)


0

Pre-calculating the Nearest function, performing the integral in polar coordinates and relaxing the patterns will give you a nice speedup (60%/80% in my experiments): SeedRandom[42]; seeds = RandomReal[{0, 1}, {100, 2}]; diam = 1; memF = Nearest[seeds]; myDist[point_] := #.# &@(point - First@memF[point]) /; VectorQ[point, NumericQ] optValue[seeds_] := ...


1

That's because, unless you request it otherwise, Mathematica will give you exact results. a = 180 u^2 - 200 u + 60 b = 30 u^2 - 100 u + 40 c = Sqrt[a^2 + b^2] Integrate[c, {u, 0, 1}] $\int_0^1 \sqrt{\left(30 u^2-100 u+40\right)^2+\left(180 u^2-200 u+60\right)^2} \, du$ is the exact result. If you want the numeric value, Apply N to the result: N@% (* ...


0

I see that right now and am a bit puzzled. Sorry for taking a full answer but I want to share some more code to explain it a bit further. I didn't find that option in the answer tab. So let me perhaps share my intial approach. At first I worked with approach that has a Rmed (in that case Rs) feature that is monodisperse. I therein used symbolic integration ...


2

The error messages are caused by arguments not being passed to function, by a conditional answer being returned by Integrate, by an infinite recurrence in the definition of zielfun, and by discontinuities in h. Additionally, unnecessary use of SetDelayed slowed the calculation. These can be eliminated as follows: R0 = 19; R1 = 46; ampshell = 0.025; alpha ...


0

The integral in your differential equation isn't the same as that in the post you linked, it can be easily eliminated if you D your equation: vdh = {x, t} \[Function] 1/(1 + h[x, t]) - h[x, t] + Log[h[x, t]/(1 + h[x, t])] λ = t \[Function] -(1/L) Integrate[vdh[x, t], {x, 0, L}] neqn = D[D[h[x, t], t] == D[h[x, t], {x, 2}] - vdh[x, t] - λ[t], x] Then ...


1

This should probably be closed as a duplicate of one of the the many NumericQ questions on this site. The problem is that LogLinearPlot attempts a symbolic evaluation, meaning that y is not given a value, and NIntegrate doesn't like this! You can use a wrapper function to prevent non-numeric y values being passed its way: f[x_, y_] := x + y^2 ...


4

I agree NDSolve is the way to go, but I think I know why there has been a slow down since V5. I believe sometime since V5 symbolic preprocessing was introduced, which can cause overhead. We can turn this off in V10 and see a drastic speed up: f[x_] := Which[-1 <= x <= 0, x, 0 <= x, x^2, True, 0] ϕ[x_] := NIntegrate[f[t], {t, -1, x}] Plot[ϕ[x], ...


1

Here is another alternative for how to speed up the plotting if you want to retain all the functionality and options of ContourPlot: use ParallelTable: f[a_?NumericQ, b_?NumericQ] := NIntegrate[a*x + b, {x, 0, 1}]; Timing[Show[ ParallelTable[ ContourPlot[f[a, b], {a, 0, 10}, {b, 0, 10}, Contours -> {i}, ContourShading -> None, ...


4

Update: Using the memoization trick suggested by @george2079 in the comments combined with MeshFunctions we get the same picture in 0.015625 seconds: fa[a_?NumericQ, b_?NumericQ] := fa[a, b] = NIntegrate[a*x + b, {x, 0, 1}]; First@Timing[ContourPlot[fa[a, b], {a, 0, 10}, {b, 0, 10}, Contours -> {}, ContourShading -> None, MeshFunctions -> ...


2

f[x_] = Piecewise[{ {x, -1 <= x <= 0}, {x^2, x > 0}}]; \[Phi][x_] = Assuming[Element[x, Reals], Integrate[f[t], {t, -1, x}]] Plot[\[Phi][x], {x, -1.5, 1}] // Timing


2

Reversing the order of integration produces a solution: ans= Integrate[HeavisideTheta[1 - x - y]/(x 100^2 - y (1 - y) 90^2), {y, 0, 1}, {x, 0, 1}, PrincipalValue -> True] (* Log[(100*10^(38/81))/(81*19^(19/81))]/10000 *) N[ans] (* 0.000060027526501455836 *) Solutions of this sort are what I would expect based on outlining a pencil-and-paper ...


5

NIntegrate[f[t], {t, -1, x}] integrates the same thing over and over again, when a point is needed by Plot. Integrate what you need one time only: f[x_] = Which[-1 <= x <= 0, x, 0 <= x, x^2, True, 0]; ϕ[x_] = NDSolve[{Derivative[1][g][t] == f[t], g[-1] == 0}, g, {t, -1.5, 1}][[1, 1, 2]][x]; Plot[ϕ[x], {x, -1.5, 1}]


8

In V10 there has been added some symbolic processing of integrands containing an InterpolatingFunction. In particular if the interpolation grid divides the domain of integration into a number of subintervals, the number being at most the value of the option "MaxSubregions", the integrand will automatically be integrated over each subinterval. In V9, this is ...


1

It turns out that in fact DiscretizeGraphics returns directly a region object, so I can do NIntegrate[1, {x, y} ∈ tt] (* 25.6601 *) or more generally, NIntegrate[x^2 y, {x, y} ∈ tt] Pretty nifty! So one could define a function NImplicitRegion[cond, rg__] := Module[{tt}, tt = ContourPlot[cond, rg, Frame -> False, ContourShading -> ...


5

reg = ImplicitRegion[{Sin[Pi x] == y, x <= 1, x >= 0}, {x, y}] This is a 1D region embedded in 2D space. NIntegrate needs to know this to produce a reasonable result. My guess is that it uses RegionDimension, which fails here: In[41]:= RegionDimension[reg] During evaluation of In[41]:= RegionDimension::nmet: Unable to compute the dimension of ...



Top 50 recent answers are included