I am trying to plot the level set of L1 norm in matlab. But it is not at all working, and I am stuck. Any help ?
x = linspace(-1,1,10);
y = linspace(-1,1,10);
[xm,ym] = meshgrid(x,y);
z = sum(abs(xm-ym));
surfc(x,y,z)
Change your fourth line into this, in accordance with the definition of L1 norm:
z = abs(xm)+abs(ym);
You could do it more efficiently using with bsxfun
to avoid generating the matrices xm
, ym
:
x = linspace(-1,1,10);
y = linspace(-1,1,10);
z = bsxfun(@plus, abs(x), abs(y).');
surfc(x,y,z)
Either of the two approaches produces:
For a better picture you should increase sampling, and perhaps remove surface edges:
x = linspace(-1,1,100);
y = linspace(-1,1,100);
z = bsxfun(@plus, abs(x), abs(y).');
surfc(x,y,z,'edgecolor','none')