Tag Info

New answers tagged

3

As pointed out by Artes, this integral has meaning only under Cauchy principal value. Luckily, NIntegrate has this strategy (explained here): NIntegrate[(4 Cos[\[Theta]] Sin[\[Theta]])/(1 - 16 Cos[\[Theta]]^4), {\[Theta], 0, \[Pi]/3, \[Pi]/2}, Method -> "PrincipalValue"] 0.127706 Note that the position of the sigularity has to be specified in the ...


1

This is not an answer but rather a comment/example on @Dr.WolfgangHintze and @halirutan posts, concerning the "weird" behaviour that was observed with NIntegrate, that is localization and symbolic evaluation of the variables which may actually lead to unwanted results: Edit I'll take an even more simple example which concerns both NIntegrate and Integrate: ...


6

Alternatively, this can be treated as a boundary-value problem. a = 1.1; b = 1.2; tf = 20; eqn = {x''[t] + (a + I*b)*x[t] == 0}; inits = {x[0] == 1, x[tf] == 0}; sys = Join[eqn, inits]; sol = NDSolve[sys, x[t], {t, 0, tf}]; Plot[Evaluate[ReIm[x[t]] /. sol], {t, 0, tf}] MichaelE2's caveat applies here too, "It might be significantly more difficult in a ...


5

If you can define an objective function that measures the size of the solution, you could optimize it. This is simple to do on the simple test case. It's a linear system, so the convergence/divergence will depend only on the ratio x'[0]/x[0]. One can optimize varying x'[t] for x[0] == 1 and test x[0] == 0 separately (best to do x[0] first, but I omit the ...


3

I rewrote your code and it works for me so I suspect there is a bug in your code. Some tips: when you write out the equation as you have done it is very easy to make mistakes. What I recomment is that you define $P=\{P_1,P_2,P_3\}$ and $Q=\{Q_1,Q_2,Q_3\}$ only once (instead of retyping it every time you need it) and then write the equation directly in ...


1

I'll leave the creation of a suitable Manipulate[] interface for somebody else; I'll just share a few ideas in this answer. First, here is a routine that generates a parabola through three points, represented as a B-spline: parabolicArc[pts_?MatrixQ] /; Dimensions[pts] == {3, 2} := BSplineCurve[ReplacePart[pts, 2 -> Mean[Delete[pts, 2]] + ...


4

Everthing woks out fine (in version 10 at least) if you take care of a consistent name of the integration variable. Let's repeat all steps 1) Table of data In[1]:= ttable = {{0, 2.6596 - 66.137 I}, {1/9, 2.45339 - 65.3148 I}, {2/9, 1.82053 - 62.8922 I}, {1/3, 0.720006 - 58.9982 I}, {4/9, -0.911205 - 53.8382 I}, {5/9, -3.15056 - 47.6797 I}, ...


5

The most important information is that you used your function ff inside another NIntegrate, because this is the source of confusion. What you have to know is that NIntegrate doesn't start right away with the numerical calculation when you call NIntegrate[ff[ξ]*ξ, {ξ, 0, 3}] It will try to do some analysis of your integrand and most likely, it will try to ...


2

Unfortunately the "shooting" is done by NDSolve`ProcessEquations, which converts the BVP into an IVP. Thus NDSolve`Reinitialize[ndssdata] is basically operating on an IVP, and you won't be able to approach your problem in this way. If we examine the state data, we see that the initial conditions are already there. {sdb, sdf} = ndssdata@"SolutionData" (* ...


5

WhenEvent[cond, act] works in time, i.e., an event happens only when a time step causes the condition cond to change from False to True, save the special cases such as f == c described in the documentation. Those subtleties aside, the main thing to understand in using WhenEvent in the method of lines is what is substituted for the dependent variables such ...


5

To get a fixed step size with the BDF method you can lower the AccuracyGoal and PrecisionGoal to increase the adaptive step sizes and then use MaxStepSize to limit the step size to any value you want. Get an example stiff system from the documentation: Needs["DifferentialEquations`NDSolveProblems`"]; Needs["DifferentialEquations`NDSolveUtilities`"]; system ...


8

You can make a change of variable to solve the problem. Here I'll use dChange for this task: r0 = 0.5; eqn = {k[z] f[z] + f'[z] == 0, k'[z] == 0, f[-1] == Exp[2], f[1] == 1}; c = Piecewise[{{r0, z > 0}}, 1]; neweqn = dChange[eqn, f[z] == c g[z]]; {solg, solk} = NDSolveValue[neweqn, {g, k}, {z, -1, 1}]; Plot[c solg[z], {z, -1, 1}]


11

Working solution One can manually implement the shooting method with ParametricNDSolveValue and FindRoot: psol = ParametricNDSolveValue[{k f[z] + f'[z] == 0, f[-1] == Exp[2], WhenEvent[z == 0, f[z] -> r0 f[z]]}, f, {z, -1, 1}, {k, r0}]; k0 = k /. FindRoot[psol[k, 0.5][1] == 1, {k, 1}] (* 0.653426 *) Plot[psol[k0, 0.5][z], {z, -1, 1}] ...


4

You lose precision using Rationalize[#, 0.000000001]& rather than Rationalize[#, 0]& For example, Rationalize[#, 0.000000001] & /@ {0.4154876, 0.0008710662} {2731/6573, 51/58549} % // N // InputForm {0.4154876007911152, 0.0008710652615757741} Which is not the original input; whereas, Rationalize[#, 0] & /@ {0.4154876, ...


4

Here's my take on it. The integrals themselves are very small (one is around 10^-626). Coincidentally that's around 10^(-2 n), so I thought to multiply by that. I haven't tested it for other values of n, but it works for n = 305 as in the example. If you have many different such integrals to do, you might spend some time analyzing this factor. ...


3

I believe this is fast enough p[x_] = Integrate[Exp[-y^2 + 2*I*y*x], {y, 0, Infinity}] Zf[x_] := 2 I p[x] f1[x_, p1_] := I*Im[Zf[x]] + p1*I*(1 + Zf[x]); f2[x_, p1_, p2_] := p1*(f1[x] + (2 + Zf[x])/Conjugate[Zf[x]]) - I*p2*(f1[x] - (2 - Zf[x])/Conjugate[Zf[x]]); Plot[Im[f1[x, 2]], {x, -2, 2}] Plot[Im[f2[x, 1.35, 1.45]], {x, -2, 2}] ...


11

It turns out ListSurfacePlot3D does a terribly poor job of approximating the surface in the OP, otherwise one will just apply DiscretizeGraphics to the output obtained from ListSurfacePlot3D and be done with it. But since that's not applicable here, we present an approach that uses alpha shapes to approximate the shape of the given point set by tuning a ...


2

Using Integrate inside NIntegrate is pointless, since the result is numerical anyways. I'd suggest: \[Theta] = \[Pi]/20; q = 3/10; g = 5/100; v = 5; w = 2/10; Z = 2; int[t_?NumericQ] := NIntegrate[BesselJ[0, x*Sin[\[Theta]]]*Exp[-x*Cos[\[Theta]]],{x, 0, q*v*t}] NIntegrate[int[t]*Exp[-g*t/2]*Cos[w*t]/t, {t, 0, \[Infinity]}, PrecisionGoal -> 12] Specify ...


2

Please behave like a good citizen of the site and read the answers you receive more carefully. The following is a direct application of my answer to your previous question here. w[k_, ω_, t_] := 1/2*k*(1 + Cos[ω t]) + 10; pnd = ParametricNDSolve[{ Paorta'[t] == 1/Caorta ((w[k,ω,t] - Paorta@t)/ Piecewise[{{ρ, w[k,ω,t] - Paorta@t ...


3

This is mostly because your code is completely unrelated to your equation. What is w? Why do you use = when you want ==? Where does the 5 come from when you want 1.5? Why are all of your initial values 0? Here is something to start with but first go to Evaluation -> Quit Kernel sol = NDSolveValue[{ u'[t] == 1.5 u[t] v[t] - u[t], v'[t] == -1.5 ...


0

Correcting the syntax errors: B[t_, i_, h_] := Piecewise[{{(t - (i - 2)*h)^3, (i - 2)*h <= t <= (i - 1)*h}, {h^3 + 3*h^2*(t - (i - 1)*h) + 3*h*(t - (i - 1)*h)^2 - 3*(t - (i - 1)*h)^3, (i - 1)*h <= t <= i*h}, {h^3 + 3*h^2*((i + 1)*h - t) + 3*h*((i + 1)*h - t)^2 - 3*((i + 1)*h - t)^3, i*h <= t <= (i + 1)*h}, ...


0

A bit late, but consider the following function: $$f_c(a,x)=\frac1{\sqrt{1+a^2}}\left(x+\arctan\left(\frac{\sin\,x\cos\,x}{a^2+a\sqrt{1+a^2}+\sin^2 x}\right)\right)$$ You can verify the following identity in Mathematica: fc[a_, x_] := (x + ArcTan[(Sin[x] Cos[x])/(a^2 + a Sqrt[1 + a^2] + Sin[x]^2)])/Sqrt[1 + a^2] D[fc[a, x], x] == a/(a^2 + Sin[x]^2) // ...


3

As noted in the Comments, this integration is plagued by precision problems. To proceed, factor the huge constant (h/(((1.989)*10^(30)))*(r^3)) u (* 3.44312*10^51 *) from the integrand and then FullSimplify and Rationalize the functions F[x, y]*G[x, y]] rat = Rationalize[FullSimplify[F[x, y]*G[x, y]], 0]; in order to achieve any possible ...


2

Another version 10 approach (barring errors on my part) to address volume as well as surface area. The (limitations of region) discretizations render only approximations, cf george2079 better numeric integration and the neat approach of Michael Seifert...both of which I have upvoted. cb = Cuboid[{-1, -1, -1}, {1, 1, 1}]; i = RegionUnion @@ ...


8

It looks like classic catastrophic round-off error. (Look at those exponents on $e$!). {sol} = DSolve[{x'[t] == y[t]/100, y'[t] == -100 x[t] - 100 y[t] + 2020, x[0] == 0, y[0] == 20}, {x, y}, t]; Now consider y[9.] vs. y[9] and y[9.`20]: y[9.] /. sol N::meprec: Internal precision limit $MaxExtraPrecision = 50.` reached while evaluating ...


6

The old fashion way: r = .5; NIntegrate[ r^2 Sin[phi] Boole[And @@ ((-1 < # < 1 ) & /@ (#[[1]] + CoordinateTransform[ "Spherical" -> "Cartesian", {r, theta, phi}]))], {theta, 0, 2 Pi} , {phi, 0, Pi} ] & /@ img // Total 25.1327 Edit: this is excluding areas that are inside any other sphere: centers ...


12

If you're running Mathematica 10 or above, there's a dead simple method using the new Area function: newimg = img /. Ball[x___, 0.6] -> Sphere[x, 0.5] Total[Map[Area[RegionIntersection[#, Cuboid[{-1, -1, -1}, {1, 1, 1}]]] &, newimg]] (* 25.1327 *) Note a few things here: Mathematica considers Ball to be a 3D object; if we want its surface area ...


3

NIntegrate can handle vector integrands if they are explicitly in vector form: f[x_] := {x, 2 x} NIntegrate[f[x], {x, 0, 1}] (* {0.5, 1.} *) When the function is a black box which will only evaluate for numeric arguments, NIntegrate no longer sees the list structure and complains about not getting a scalar value: g[x_?NumericQ] := {x, 2 x} ...


8

For what it's worth, you can monitor the progress of Integrate and NIntegrate. I'm not sure how helpful the tools below are, but I feel it is probably worth mentioning them. Integrate Internal`Integrate`debugSwitch If you set Internal`Integrate`debugSwitch to the magic number 10, it will print its (major) steps in searching for the answer. For instance: ...


5

Define: integ[p_?NumericQ] := NIntegrate[f[x, p], {x, a, b}] Then plot it: Plot[integ[p],{p,10,100}]


6

There probably cannot be general answer for such a general question because the bigger integrand (other conditions being equal) the more time Integrate needs to handle it. But for basic tabular integrands there are some benchmarks made by Albert Rich, the developer of Rubi - rule-based integrator. On the linked page a table is given where the "Timeout" ...


2

Problems of this sort are posted from time to time in Mathematica SE. Multiple instances of Nintegrate are nested one inside another, and an inner integrand contains one of the outer variables of integration. And, from the point of view of the inner NInterate, the outer variable is undefined. (Chuy noted this in a comment above.) The solution is to have ...


4

A WhenEvent[event, action] can be included in the list eqn used in NDSolve[eqn,__]. For example: eqn = { p'[r] == -p[r] - 1, p[0] == 1, WhenEvent[p[r] == 0, rMax = r; "StopIntegration"] }; sol = NDSolve[eqn, p, {r, 0, \[Infinity]}]; Plot[p[r] /. sol, {r, 0, rMax}]



Top 50 recent answers are included