I want to solve a convolution integral numerically:
Dx=1;tau=5;
Ex[x_] := (1/Sqrt[4*Pi*Dx*x])*Exp[-((x - tau)^2/(4*Dx*x))];
Fnum[x_]:=NIntegrate[A[xprime]*Ex[x-xprime], {xprime, 0, x},MaxRecursion->20]
As a test, I am using a step function for the function A[x]
by setting
A[x_]:=If[x0<=x<=x0+dx, A0, 0]
where, for instance, x0=0; dx=1; A0=1;
In this specific case, the integral can also be solved analytically and the result is Fan[x_]:=A0*dx*Ex[x-x0]
.
However, when I plot, I notice that the analytical solution and the numerical solution are different.
Plot[{Fnum[x], Fan[x]}, {x, 0, 30}, PlotRange -> {{0, 30}, All},
GridLines->Automatic, PlotStyle->Thick,ImageSize->Large]
Ex[x_] := 1
, and observe the discrepancy. Your result is correct only in the $\mathrm d x \to 0$ limit. $\endgroup$Fan[x_]
? $\endgroup$