I'm a MATLAB newbie having trouble writing a program to mollify the Heaviside function. I've been looking all over the place and asking around, including at Stack Overflow, but I've had no luck. I know that this isn't exactly the place for a MATLAB question, but I've had good luck here before. If there is another place where this question would be more appropriate, please let me know.
At any rate, I'm trying to mollify the Heaviside function using the bump function $$ \phi(x) = \left\{ \begin{array}{lr} e^{-1/(1-x^2)} & : \ |x| < 1\\ 0 & : \ |x| \geq 1 \end{array} \right.$$
If $\Phi$ is the normalized version of $\phi$ and $h(x)$ is the Heaviside function, I'm trying to write code to approximate the integral $$\Phi_{\epsilon}(x) = \epsilon^{-1}\int_{\mathbb{R}^d} \Phi\left(\frac{x-y}{\epsilon}\right)h(y) \ dy$$
To that end, I have written the nested function smooth in MATLAB:
function s = smooth(x,y,e)
s = e.^(-1)int(mbump(x,y,e), x = -2..2);
mbump(x,y,e)
function m = mbump(x)
m = cbump(x,y,e).*heaviside(y);
cbump(x,y,e)
function c = cbump(x,y,e)
c = nbump(quot(x,y,e));
nbump(t)
quot(x,y,e)
function n = nbump(t)
n = bump(t)*(ibump(t)).^-1;
ibump(t)
function i = ibump(t)
i = integral(@bump, -2, 2);
bump(t)
function b = bump(t)
region1 = abs(t) = 1;
b(region2) = 0;
end
function q = quot(x,y,e)
q = (x-y)./e;
end
end
end
end
end
end
Also, please forgive my formatting. The definition of smooth should be to the left of the body as should the final end. It's like this in my code, but I don't know how to get the formatting right here.
This probably isn't the most elegant way to implement this function. Anyway, when I try and run plot(x, smooth(x,y,e)), I get the error Unexpected MATLAB expression. I know there must be something wrong with how I'm trying to integrate and I've tried several different ways, all of which don't work. Anyway, any advice on how to fix this would be greatly appreciated.
Thanks.