Hello,
I am trying to evaluate an integral of a function (as part of a cross-check between my own results and the results from a piece of literature), however I'm struggling to get MATLAB to integrate what for all intents and purposes is a relatively well behaved function (though admittedly it is a fairly complicated one).
See the example code below which I have streamlined a bit for readability. I setup some initial parameters (physical dimensions and a dimensionless energy or lorentz factor), setup a positional array and then rescale it as well as defining a dimensionless parameter, eta. Then I simply run the integral for different values of the dimensionless position array d. (I'm aware I could use the array valued feature of integral to do it without the loop but it's besides the point)
z = -zdomain+dz/2:dz:zdomain-dz/2;
HS = @(x) -1/(4*sqrt(pi)).*(sqrt(pi).*abs(x)+pi*(1-x.^2/2).*exp(x.^2/4).*erfc(abs(x)/2));
GS(j) = integral(@(x) HS(d(j)-x).*exp(-x.^2/(2*eta^2)),-inf,inf);
This integrand behaves as follows for d=0, and for the parameter values chosen behaves pretty closely to the kernel, HS.
Running the code, I get NaN values for all d (s), and MATLAB seems to decide very quickly that the integral isn't going to work. I don't understand why but I have the feeling I've missed something obvious. Is there some way in which I've written HS(x) badly?
Thanks!