clc,clear
x = -3:0.1:3;
s=size(x);
y=zeros(s(1),s(2));
for i=1:s(2)
y(i)=rect(x(i)/2);
end
plot(x,y)
ylim([min(y)-1 max(y)+1])
function y = rect(x)
y=1.*(abs(x)<1/2)+1/2.*(abs(x)==1/2)+0.*~((abs(x)<1/2)|(abs(x)==1/2));
end
clc,clear
x = -9:0.1:3;
s=size(x);
y=zeros(s(1),s(2));
for i=1:s(2)
y(i)=tri((x(i)+2)/2);
end
plot(x,y)
ylim([min(y)-1 max(y)+1])
function y = tri(x)
ax=abs(x);
y=(1-ax).*(ax<1)+0.*~(ax<1);
end
clc,clear
x = -10:0.1:10;
y=exp(-3*pi*(x.^2));
plot(x,y)
ylim([min(y-1) max(y+1)])
clc,clear
x=-10:0.1:10;
s=size(x);
y=zeros(s(1),s(2));
for i=1:s(2)
y(i)=[comb(x(i)/4)*tri(x(i))]*rect(x(i)/12);
end
plot(x,y)
ylim([min(y)-1 max(y)+1])
function y = comb(x)
syms n;
y=eval(int(dirac(x-n),n,-inf,inf));
end
function y = tri(x)
ax=abs(x);
y=(1-ax).*(ax<1)+0.*~(ax<1);
end
function y = rect(x)
y=1.*(abs(x)<1/2)+1/2.*(abs(x)==1/2)+0.*~((abs(x)<1/2)|(abs(x)==1/2));
end
clc,clear
t = -3:0.1:3;
[x,y] = meshgrid(t);
s=size(x)
z=zeros(s(1),s(2));
for i=1:s(1)
for j=1:s(2)
z(i,j)= circ(x(i,j)-2,y(i,j))+circ(x(i,j)+2,y(i,j));
end
end
mesh(x,y,z)
function z=circ(x,y)
z=1.*(sqrt(x^2+y^2)<1/2)+...
(1/2).*(sqrt(x^2+y^2)==1/2)+...
0.*~((sqrt(x^2+y^2)<1/2)|(sqrt(x^2+y^2)==1/2));
end