Community RSS Feed https://community.wolfram.com RSS Feed for Wolfram Community showing any discussions in tag Signal Processing sorted by active How to speed up the integral in NDSolve? https://community.wolfram.com/groups/-/m/t/1741959 Dear Mathematica users, I posted a [problem] on MMA.SE several days ago, which, however, attracted little attention. So I ask for help on the dedicated technical forums, where I hope many experienced users are present. On the MMA.SE, there have been several question on how to solve integro-differential equations using NDSolve, see [example 1], [example 2], and [example 3]. Many people, like me, have a hard time with this kind of problem. I had raised the last one 5 months ago and obtained a promising answer, since then I have been tried to solve the following equation for a spatially periodic function $u(x,t)$ on $[-L,L]$ with $2L$ periodicity: $$\partial_t u + u\partial_x u + \partial_x^2 u +\partial_x^4 u + a{\rm{int}}[\partial_x^3u] + bu^3 {\rm{int}} [(\partial_x^2u) {\rm{int}}[\partial_x u] ] = 0, \tag{1}$$ where $a$ and $b$ are constants, and $\rm{int}[f]$ is a spatial integral for a periodic function $f(x,t)$ $${\rm{int}}[f](x,t)=\frac{1}{2L}\mathrm{PV}\int_{-L}^L f(x^\prime,t)\cot\left[\frac{\pi(x-x^\prime)}{2L}\right]\:\mathrm{d}x^\prime, \tag{2}$$ which should be understood in the sense of principal value (PV) since there is a singularity at $x=x^\prime$. This equation is subjected to periodic boundary conditions and an initial condition. In my real problem, it has several $\rm{int}$ terms and its nest, like ${\rm{int}}[(\partial_x^2u) \rm{int}[\cdots] ]$, which will be solved over a large domain and a long time, say, $L=30$ and $t_\text{max}=200$ (much larger than those in my [original post]). I tried [Michael&#039;s answer] but found that even for that simplified version of Eq.(1) (without the last nested term) the code is extremely slow, though it works. Actually, I also posted [my answer] based on the finite difference method, but the accuracy of my code is not as good as Michael&#039;s. (That is why I didn&#039;t accept any answer.) Also, the problem has stiffness due to the high-order derivatives and nonlinear terms. So I have added some Method options to NDSolve ProcessEquations. **The Mathematica code** L = 30; tmax = 30; a = 1; b = 1/100; c = 1/(2 L); e = 1/10; nGrid = 91; ic[x_] = e*Cos[\[Pi]*x/L]; sys = {D[u[x, t], t] + u[x, t]*D[u[x, t], x] + D[u[x, t], {x, 2}] + D[u[x, t], {x, 4}] + a*int[D[u[x, t], {x, 3}], x, t] + b*u[x, t]^3*intnest[D[u[x, t], {x, 2}]*int[D[u[x, t], x], x, t], x, t] == 0, u[-L, t] == u[L, t], u[x, 0] == ic[x]}; periodize[data_] := Append[data, {N@L, data[[1, 2]]}];(*for periodic interpolation*) Block[{int, intnest}, (* IC fools ProcessEquations to consider int[] as a good num.fn.*) int[uppp_, x_?NumericQ, t_ /; t == 0] := (cnt++; c*NIntegrate[D[ic[xp], {xp, 3}]*Cot[\[Pi] (x - xp)/(2*L)], {xp, x - L, x, x + L}, Method -&gt; {&#034;InterpolationPointsSubdivision&#034;, Method -&gt; {&#034;PrincipalValue&#034;, &#034;SymbolicProcessing&#034; -&gt; 0}}, PrecisionGoal -&gt; 8, AccuracyGoal -&gt; 8, MaxRecursion -&gt; 10]); int[uppp_?VectorQ, xv_?VectorQ, t_?NumericQ] := Function[x, cnt++; c*NIntegrate[Interpolation[periodize@Transpose@{xv, uppp}, xp, PeriodicInterpolation -&gt; True]*Cot[\[Pi] (x - xp)/(2*L)], {xp, x - L, x, x + L}, Method -&gt; {&#034;InterpolationPointsSubdivision&#034;, Method -&gt; {&#034;PrincipalValue&#034;, &#034;SymbolicProcessing&#034; -&gt; 0}}, PrecisionGoal -&gt; 8, AccuracyGoal -&gt; 8, MaxRecursion -&gt; 10]] /@xv; intnest[upp_, x_?NumericQ, t_ /; t == 0] := (cnt2++; c*NIntegrate[D[ic[xp], {xp, 2}]*int[D[ic[xp], xp], x, t]*Cot[\[Pi] (x - xp)/(2*L)], {xp, x - L, x, x + L}, Method -&gt; {&#034;InterpolationPointsSubdivision&#034;, Method -&gt; {&#034;PrincipalValue&#034;, &#034;SymbolicProcessing&#034; -&gt; 0}}, PrecisionGoal -&gt; 8, AccuracyGoal -&gt; 8, MaxRecursion -&gt; 10]); intnest[upp_?VectorQ, xv_?VectorQ, t_?NumericQ] := Function[x, cnt2++; c*NIntegrate[Interpolation[periodize@Transpose@{xv, upp}, xp, PeriodicInterpolation -&gt; True]*Cot[\[Pi] (x - xp)/(2*L)], {xp, x - L, x, x + L}, Method -&gt; {&#034;InterpolationPointsSubdivision&#034;, Method -&gt; {&#034;PrincipalValue&#034;, &#034;SymbolicProcessing&#034; -&gt; 0}}, PrecisionGoal -&gt; 8, AccuracyGoal -&gt; 8, MaxRecursion -&gt; 10]] /@xv; (*monitor while integrating pde*) Clear[foo]; cnt = 0; cnt2 = 0; PrintTemporary@Dynamic@{foo, cnt, cnt2, Clock[Infinity]}; (*broken down NDSolve call*) InternalInheritedBlock[{MapThread}, {state} = NDSolveProcessEquations[sys, u, {x, -L, L}, {t, 0, tmax}, Method -&gt; {&#034;MethodOfLines&#034;, &#034;SpatialDiscretization&#034; -&gt; {&#034;TensorProductGrid&#034;, &#034;MinPoints&#034; -&gt; nGrid, &#034;MaxPoints&#034; -&gt; nGrid, &#034;DifferenceOrder&#034; -&gt; &#034;Pseudospectral&#034;}, Method -&gt; {&#034;StiffnessSwitching&#034;, &#034;NonstiffTest&#034; -&gt; Automatic}}, AccuracyGoal -&gt; Infinity, WorkingPrecision -&gt; 20, MaxSteps -&gt; \[Infinity], StepMonitor :&gt; (foo = t)]; Unprotect[MapThread]; MapThread[f_, data_, 1] /; ! FreeQ[f, int] := f @@ data; Protect[MapThread]; NDSolveIterate[state, {0, tmax}]; sol = NDSolveProcessSolutions[state]]] // AbsoluteTiming **My problem** As mentioned above, the code is very slow. An estimation: $&gt;2$ hrs may be required to obtain convergence with tmax = 1. Btw, the &#034;slwcon&#034; and &#034;ncvb&#034; warning could be ignored (see Michael&#039;s comments following his answer there). Is there any approach that would help speed up the code? Thank you very much. **Some ideas** As suggested by Henrik Schumacher, the combination of NIntegrate and Interpolation limits the speed of this code. Maybe it could be better to use a fixed quadrature rule and implement the integration with ListConvolve. But I need help with implementing this idea in my problem, so I bring this problem here in the hope that someone could help. I am thinking that can we divide the interval into a uniform grid with $2M$($=\rm{nGrid}-1$) mesh points defined by $x_m=(m-M)h$, where $h=L/M$. Please see also [my answer] to a similar problem. Then the integral term (2) could be evaluate at the midpoints $x_{i+1/2}=(x_i+x_{i+1})/2$, for $i=0,1,\ldots,2M-1$, (note the periodicity demands $u_0=u_{2M}$) using a certain integration rule, e.g., trapezoidal rule, with $x_i$ as integration nodes. In this way, **the principal value integral could be efficiently computed, as if it were simply an ordinary integral.** : https://mathematica.stackexchange.com/questions/202230/speed-up-ndsolve-for-an-integro-differential-equation?noredirect=1#comment522836_202230 : https://mathematica.stackexchange.com/questions/183356/solve-integro-differential-equations : https://mathematica.stackexchange.com/questions/148541/numerically-solve-an-integro-differential-equation : https://mathematica.stackexchange.com/questions/192123/solving-an-integro-differential-equation-with-mathematica : https://mathematica.stackexchange.com/questions/192123/solving-an-integro-differential-equation-with-mathematica : https://mathematica.stackexchange.com/a/192736/55777 : https://mathematica.stackexchange.com/a/192722/55777 : https://mathematica.stackexchange.com/questions/200270/solving-partial-differential-equation-involving-hilbert-transform : https://mathematica.stackexchange.com/a/192722/55777 Tom Wolfram 2019-07-20T05:37:19Z Audio data plot https://community.wolfram.com/groups/-/m/t/1738397 I am a beginner in mathematica. Currently i am working on audio file my problem is when i extract audio information using BinaryReadList and try to plot it works with mono wav file but cannot get with sterio file. Can anyone help me where i went wrong or how i can get it right. Here a1.wav is a single(mono) channel audio while bird.wav is dual(sterio) channel. Motilal khoirom 2019-07-16T17:39:43Z SystemModeler functionality in the V12 Mathematica distro for RasPi https://community.wolfram.com/groups/-/m/t/1737932 I recently discovered that my full version of V12 for Mac has at least a good subset of SystemModeler functionality now included in the Mathematica package. When I loaded the new V12 for the Raspberry Pi, it appeared that SystemModeler was not included in that distro. Can that package be loaded, or is it planned to be included? I personally don&#039;t need it on the Pi, but some STEM students might find it useful. Steve Steve R 2019-07-15T23:56:56Z