With respect to code effiency: In vs 6 the FourierCosTransform have timings of 4 s and 0.2 s. Try vs 13: 7s and 104 s, on a 4* faster machine.
NIntegrate on FourierTransform is a misunderstanding of the idea.
FourierTransform is a concept to generate distributions, multiply them by the FourierTransorm of some smooth functions, with compact support eg, so that the back transformation works, and transform back the product.
If the distribution formally solves an equation, involving only linear combinations of derivatives and integrals, then this object solves the equation and, by definition, at t=0 has the given start value.
Or one multiplies the Fourier transform by a filter and manipulates each color or audio frequency. This is linear invertible filtering by modes.
NIntegrate is never used practically for this purpose, it's to slow.
It is orders of magnitude faster, to transform, on a lattice of Length/2^n, back and forth in real time.
NIntegrate does the same but has not that effective method of Fourier: reducing in fact the algebra to a recursion of calculating differences and sus of next neighbors x_i +- x_i+1 only.
But there is another reason never to use NIntegrate: 99,9999% of all Fourier transforms are calculated by projecting it on the Riemann sphere map of the complex plane (the sphere standing with south pole at z=0 with radius 2, map by rays from the north pole to the plane).
The integral goes over the poles along the image of the real line. If one succeds to find another meridian, yilding an integral of exact zero, one has a closed path, that can be deformed as long as the integrand is analytic.
Finally there remain integrals around poles (z-z_k)^-1, higher order poles don't contibute.
Or there are branch cuts as for square roots of polynomials, than the path will be contracted to encircle the cuts between the zeros under the square root.
In any case, one finally gets a sum over residues, thats the value at the simple poles divided by the jump of the argument from -1 to -1, but on a circle giving 2 pi I as Length independent of the radius.
No NIntegrate can pull out these values from the haystack, if the path is R.
The numerical reason is, that Nintegrate cannot catch up with fast oscillating functions in general.
But the abstract Fourier transforn is exactly doing this by using the Lebesgue integral.
The Lebesgue integral has no problems as long the summed values within a partition, eg in rectangles, of the target complex plane of values, times the volume of thats rectangles pre-images converge.
Sqrt[2/Pi]* NIntegrate[K2[t]*Cos[0.1*t], {t, 0, 20}, Method -> {"Trapezoidal", "SymbolicProcessing" -> 0}]? – Mariusz Iwaniuk May 03 '23 at 11:58InverseFourierCosTransform[K1[Z], Z, t]. The integral clearly diverges. The command of Maple 2023 (the analog ofInverseFourierCosTransformin Maple)inttrans:-fouriercos(3*(-4*Z^2 + 1)/(2*(Z^2 + 1)^(7/2)), Z, t)results in $$ \frac{\sqrt{2}, t^{2} \left(t \mathrm{BesselK}! \left(3,t\right)+4 \mathrm{BesselK}! \left(1,t\right) t-4 \mathrm{BesselK}! \left(2,t\right)\right)}{10 \sqrt{\pi}}.$$ – user64494 May 03 '23 at 15:40Out[273]= 3/2 - 3/4 (15 + t^2) z^2
Out[274]= (45/(2 z^7) - 6/z^5) Cos[t z]`
– Daniel Lichtblau May 03 '23 at 16:15K2[t], notK1[t]in the integrand. Look at the results ofPlot[1/(5 Sqrt[ 2 \[Pi]]) (t^3 BesselK[3, t] - 16 MeijerG[{{-(1/2)}, {}}, {{0, 2}, {1/2}}, t^2/4])* Cos[0.1*t], {t, 0, 50}]andNIntegrate[(1/(5 Sqrt[2 \[Pi]])) (t^3 BesselK[3, t] - 16 MeijerG[{{-(1/2)}, {}}, {{0, 2}, {1/2}}, t^2/4])* Cos[0.1*t], {t, 0, 500}]. – user64494 May 03 '23 at 16:37K2 = (t^3 BesselK[3, t])/(5 Sqrt[2 \[Pi]]) - InverseMellinTransform[ MellinTransform[ 8/5 Sqrt[2/\[Pi]] MeijerG[{{-(1/2)}, {}}, {{0, 2}, {1/2}}, t^2/4], t, s], s, t] // FullSimplify; FourierCosTransform[K2, t, Z]. – Mariusz Iwaniuk May 03 '23 at 17:18{Plot[K2*Cos[1/10*t], {t, 0, 50}, PlotRange -> All], Sqrt[2/Pi]*NIntegrate[K2*Cos[1/10*t], {t, 0, Infinity}]}:P – Mariusz Iwaniuk May 03 '23 at 17:23InverseMellinTransform@MellinTransform? In other case that is built on the sand as other speculations of you. – user64494 May 03 '23 at 17:37NIntegrate[K2[t]*Cos[0.1*t], {t, 0, Infinity}]. – user64494 May 04 '23 at 10:54Out[20]= {t^2/Sqrt[2 [Pi]], E^-t (-(9009/(65536 t^(3/2))) + 693/(2048 Sqrt[t]) + (189 Sqrt[t])/ 256 + (7 t^(3/2))/16 + t^(5/2)/10) + E^-t (-(((1/4 - I/4) (-1)^(1/4) t^(3/2))/Sqrt[ 2]) + (1/5 - I/5) (-1)^(1/4) Sqrt[2] t^(5/2))}`...
– Daniel Lichtblau May 04 '23 at 14:40