Tag Info

New answers tagged

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


3

Here is a rigorous way to deal with the integration problem, making use only of the assumption that the integral is convergent so that we can exchange the integration and the series expansion for the Coulomb function: f[r_] := r^n E^(-r (1 + μ)) E^(-I k r) Hypergeometric1F1[I/k + 1, 2, 2 I k r]; g = f[r] /. {n -> 0, μ -> 0} (* ==> E^(-r - I ...


2

Define arg = r^n Exp[-r (1 + mu + I k)] Hypergeometric1F1[1 + I/k, 2, 2 I k r] Then, performing the inner integral in the Question, complete with Assumptions, Integrate[arg, {r, 0, Infinity}, Assumptions -> {k > 0, mu ∈ Reals, n ∈ Integers, n >= 0}] yields a ConditionalExpression with highly restrictive conditions, n < 1 && mu == ...


1

In my opinion, WhenEvent is still a wild beast in Mathematica, actually the only example for handling PDE with WhenEvent in the document only sets a "StopIntegration" event. Indeed, WhenEvent is able to do more, but quite tricky, see this post for example. For your problem, I think using Piecewise is a possible solution: T = 1; pde = D[f[t, x], {t, 1}] + ...


1

You can also use Solve Solve[Integrate[ (x^2 - .0015 x^4)/D[(x^2 - .0015 x^4), x], {x, 1.414, v}] == 50, v, Reals][[1]] // Quiet {v -> 12.9905}


1

s[v_?NumericQ] := NIntegrate[(x^2 - .0015 x^4)/D[(x^2 - .0015 x^4), x], {x, 1.414, v}] FindRoot[s[v] == 50, {v, 11}] (* {v -> 12.9905} *)


0

To try to avoid some badness from numerical integration of the Cos, I tried to simplify things by first integrating out the tau Integrate[ Exp[-(T - tau)*(lambda1^2 + lambda2^2)^3]*(D[ Exp[-zeta1^2 - zeta2^2 - tau^2], {zeta1, 2}] + D[Exp[-zeta2^2 - zeta1^2 - tau^2], {zeta2, 2}])/(2*Pi)^(3/ 5), {tau, 0, T}] Which is: ...


3

Alternatively, use FindRoot FindRoot[Integrate[ SquareWave[{0.2, 0}, ((x - 2.5)/10)], {x, 0 + a, 10 - a}] == 0.95, {a, .5}] {a -> 0.125}


3

Solve[{Integrate[ SquareWave[{2/10, 0}, ((x - 25/10)/10)], {x, a, 10 - a}, Assumptions -> 0 < a < 1] == 95/100, 0 <= a <= 1}, a, Reals] (* {{a -> 1/8}} *)


4

Using the final substitution given in the Question with the addition of Method -> "StiffnessSwitching" produces a solution for r2 as large as 7.4, after which even "StiffnessSwitching" is insufficient to treat the equations at f and h very near 1. λ = 625/2048; r1 = 10^-6; r2 = 7.4; eqn = {r^2*D[D[f[r], r], r] == 2 f[r] (1 - f[r]) (1 - 2 f[r]) - ...


1

I think it just does not converge. In general high dimensional (>4) integral always converge fastest with monte carlo method. k = 0; Dynamic[k] NIntegrate[ Exp[-(T - tau)*(lambda1^2 + lambda2^2)^3]* Cos[(X - zeta1)*lambda1 + (Y - zeta2)* lambda2]*(D[Exp[-zeta1^2 - zeta2^2 - tau^2], {zeta1, 2}] + D[Exp[-zeta2^2 - zeta1^2 - tau^2], {zeta2, ...


1

Some issues one can spot: Some dependent variables are functions of M and R, some of n and R. While M and n appear as independent variables in the equations, for example, M[1][n, R] and n[1][M, R], they are not listed as integration variables. You have initial conditions for M[0] and n[0] but no corresponding differential equation. M and n appear both ...


4

Use ComplexExpand Integrate[ComplexExpand[Re[Exp[I*Omega*t]]], {t, 0, 2 Pi}] Sin[2*Omega*Pi]/Omega


3

Integrate[Cos[a t], {t, 0, 2 Pi}] or the somewhat messy: Integrate[ Simplify[Re[ExpToTrig[Exp[I a t]]], Assumptions -> {a \[Element] Reals, t \[Element] Reals}], {t, 0, 2 Pi}] =>Sin[2 a \[Pi]]/a


1

According to your definition we have g[x_] := (x + 1) Log[x + 1] - x Log[x] The two functions performing the numerical integration are fC[a_] := NIntegrate[g[1/(Exp[1/x] - 1)], {x, 0, a}] fP[a_] := NIntegrate[1/(x/(Exp[1/x] - 1)), {x, 0, a}] Remarks 1) variable names must begin with a lower case letter, hence I have written fC and fP instead of C and ...


6

Starting with an extension to the point raised in your edit. rL = RandomReal[{0.5, 1.5}, 10000]; timings = Table[{10^n, AbsoluteTiming[Exp[-(rL*10^n)]][[1]]}, {n, 0, 5, .01}]; ListLogLinearPlot[{timings, {{746, 0}, {746, 0.05}}}, AxesLabel -> {"Scaling", "Time"}, Joined -> {False, True}, PlotStyle -> {Black, Red}] The red vertical line is ...


1

There was a really silly mistake. I'm embarrassed for even asking now... z = r cos[theta] was missing from the integral. It's all good now. Thanks for the help anyways! Love you guys :]


0

As the following code suggests, a lot of spikes in the integrand means that several different numerical answers should be obtained when representing the data by means of more or less smooth functions (in the code the function is obtained by Interpolation and its smoothness depends on the parameter named order): a = -50; b = 50; Table[SeedRandom[5]; datax = ...


1

(If this doesn't help, then I think you will have to post your own example.) Random data: SeedRandom[1]; data = Sort@ Transpose[{{0, 1000}~Join~RandomReal[{0, 1000}, 10000 - 2], RandomReal[{-5, -4}, 10000 - 100]~Join~RandomReal[{4, 5}, 100]}]; ifn = Interpolation[data] For the integrand I'll use ifn[x]^2. It does have about 100 spikes randomly ...


1

You don't even need to numerically integrate. Each of your intended integrals is simply: $$\int_0^\infty e^{-k x^2}dx={1\over 2}\sqrt{\pi\over k}$$ Also you don't need to evaluate a bunch of Bessel functions, since BesselJZero[1/2,n] is $n\pi$. As noted by @belisarius, your first term would diverge if you integrate to $\infty$, since the integrand is 1. ...


4

By taking advantage of the trigonometric identity, 2 Sin[m π χ] Sin[p π χ] == Cos[(m - p) π χ] - Cos[(m + p) π χ] the number of integrals to be performed can be reduced from Nmax^2 to 2*Nmax+1, as savings of nearly a factor of 40 for Nmax = 80. Nmax = 80; dct = Table[Integrate[Cos[i π χ] V[χ], {χ, 0, 1}], {i, 0, 2 Nmax}]; Hmp = Table[(p^2 π^2)/2 ...


3

To get the warning Raise the PrecisionGoal: NIntegrate[BesselJ[2, x], {x, 0, 50000}, PrecisionGoal -> 10] NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in x near {x} = {97.6563}. NIntegrate obtained -0.00247946 and 0.004932015473174114` for the integral and error estimates. >> (* -0.00247946 ...


4

Parallelize[ Do[NIntegrate[BesselJ[2, x], {x, 0, 10000}], {i, 1, 100}] ] // AbsoluteTiming on same PC clc clear all; f = @(x) besselj(2,x); tic for i=1:100 integral(f,0,10000); end toc %Elapsed time is 0.924171 seconds. Just to note, tic/toc and AbsoluteTiming measure elapsed time, not cpu time. On mutlicore, it is possible that elapsed time is ...


2

This looks like a bug. May be another branch cut bug. So, Mathematica can't throw an error, since it does not know that it is a bug. sol = Integrate[BesselJ[2, x], x]; N[Limit[sol, x -> 50000] - Limit[sol, x -> 0]] (* 1.00248 *) The problem is in the NIntegrate when it evaluated the limits. sol = N[Integrate[BesselJ[2, x], {x, 0, 50000}]] ...


1

fixing the Cos typo and making a bold decision that the xrange ends at 4 Pi not 10 ClearAll["Global`*"]; pdeset = {Derivative[1, 0][U][t, x] == Derivative[0, 2][U][t, x], Derivative[1, 0][T][t, x] == Derivative[0, 2][T][t, x] + E Derivative[0, 1][U][t, x]^2} ics = {U[0, x] == 0, T[0, x] == 0}; bcs = {U[t, 0] == Cos[t], U[t, 4 Pi] == 0,T[t, 0] == 1, ...


7

Using the Method option with the following settings seems to work: NIntegrate[Sin[81 x]/((2^x + 1) (Sin[x])), {x, -Pi/2, Pi/2}, Method -> "LevinRule"] NIntegrate[Sin[81 x]/((2^x + 1) (Sin[x])), {x, -Pi/2, Pi/2}, Method -> "LocalAdaptive"] NIntegrate[Sin[81 x]/((2^x + 1) (Sin[x])), {x, -Pi/2, Pi/2}, Method -> ...


2

Integrate[1/((1 - y)*y^2*Sqrt[1/2 - y^2 + y^3]), y] // ToRadicals Gives you the symbolic thing


3

The numerical result you received on WolframAlpha is the result of a numerical integration: NIntegrate[1/((1 - y) y^2 Sqrt[0.5 - y^2 + y^3]), {y, 0.2, 0.5}] 6.68687 Or N@Integrate[1/((1 - y)*y^2*Sqrt[0.5 - y^2 + y^3]), {y, 0.2, 0.5}] 6.68687


3

The problem is that the "DiscontinuityProcessing" stage of NSolve seems to supersede the WhenEvent. One way is too use use Method -> {"DiscontinuityProcessing" -> False}, but that is highly inefficient. A better way is to prevent Sign from being analyzed by wrapping it in a numeric black box and include a "CrossDiscontinuity" event at x[t] == 0. ...


2

Given that ParametricNDSolve does not handle this case, one can revert to the old way. Uncomment the memoization if desired; it will speed things up if sol is called multiple times with the same parameters. Clear[sol]; sol[t0_, x0_, y0_, ϵ_] := (*sol[t0, x0, y0, ϵ] =*) NDSolve[{x'[t] == y[t], y'[t] == x[t] - 1 - ϵ Cos[5 t], x[t0] == x0, y[t0] == ...


5

Apparently, ParametricNDSolve cannot handle x[t0] or y[t0] when t0 is a parameter. A work-around is to shift time to begin at t0, in which case the code becomes, sol = ParametricNDSolve[{x'[t] == y[t], y'[t] == x[t] - 1 - \[Epsilon] Cos[5 (t + t0)], x[0] == x0, y[0] == y0}, {x, y}, {t, -t0, -t0 + 10}, {t0, x0, y0, \[Epsilon]}] which works fine. ...


3

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


5

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



Top 50 recent answers are included