0
votes

MATLAB newbie here. I'm trying to make a smooth approximation to the Heaviside function heaviside(x). To that end, I'm doing a standard mollification procedure with a bump function. Here is the nested function smooth that I think should carry out the process (I'm sorry if it's an inelegant solution).

function c = smooth(q,y,e)
c = e.^-1*int(igrand(q,y),y,-2,2);
igrand(q,y)

function i = igrand(q,y)
i = dbump(q)*heaviside(y);
dbump(q)

    function d = dbump(q)
    d = compose(nbump,quot,x,q);
    nbump(x);
    quot(x,y,e);


        function n = nbump(x)
        n = bump(x)*(ibump(x)).^-1;
        ibump(x)

            function i = ibump(x)
            i = integral(@bump, -2, 2);
            bump(x)

                function b = bump(x)
                region1 = abs(x) < 1;
                b(region1) = (exp(-1./(1 - x(region1).^2)));

                region2 = abs(x) >= 1;
                b(region2) = 0;

        function q = quot(x,y,e)
        q = (x-y)./e;
        end
                end
            end
        end
    end
end

end

Also, forgive my formatting. The last end should be to the left of the preceding one. Also, the definition of smooth should be to the left of the rest of the body.

I choose x = -2:.01:2, e = .1 and syms y real. However, when I run plot(x, smooth(q,y,e)), I get the following error.

Error using smooth/igrand/dbump/nbump (line 16)
Not enough input arguments.

Error in smooth/igrand/dbump (line 10)
d = compose(nbump,quot,x,q);

Error in smooth/igrand (line 6)
i = dbump(q)*heaviside(y);

Error in smooth (line 2)
c = e.^-1*int(igrand(q,y),y,-2,2);

The only error that shows up when I'm actually writing the function is an underline under quot near the bottom that says that the function may be unused. But, aren't I composing it with nbump?

Edit: I've changed compose(nbump,quot,x,q); to just nbump(quot(x,y,e)); and I've changed all of the variables so that they line up (no more q's). Now, when I run plot(x,smooth(x,y,e)), it runs for a while, then stalls and gives me the following error messages.

Error using symengine (line 58)
Unable to prove 'abs(10*y + 20) < 1' literally. To test the statement mathematically, use isAlways.

Error in sym/subsindex (line 1554)
X = find(mupadmex('symobj::logical',A.s,9)) - 1;

Error in sym>privformat (line 2357)
x = subsindex(x)+1;

Error in sym/subsref (line 1578)
[inds{k},refs{k}] = privformat(inds{k});

Error in bump (line 3)
b(region1) = (exp(-1./(1 - x(region1).^2)))

Error in smooth/igrand/dbump/nbump (line 16)
n = bump(x)*(ibump(x)).^-1;

Error in smooth/igrand/dbump (line 10)
d = nbump(quot(x,y,e));

Error in smooth/igrand (line 6)
i = dbump(x,y,e)*heaviside(y);

Error in smooth (line 2)
s = e.^-1*int(igrand(x,y,e),y,-2,2);

1
I might be wrong, but I don't think compose is as powerful as you think it is. What happens when you take the semicolon off the compose statement? d = compose(nbump,quot,x,q) - dmm
For numerical integration, use integral() or related (in the see also section) - Oleg

1 Answers

0
votes

As the error says, you are calling nbump without inputs:

Error in smooth/igrand/dbump (line 10)
d = compose(nbump,quot,x,q);