Matlab plot 2D p-norm

968 Views Asked by At

I want to plot the p-norm in a 2 dimensional space with the condition $|x,y|_p = 1$

x = linspace(-1,1,10);
y = linspace(-1,1,10);
[xm,ym] = meshgrid(x,y);

for p=1:5
    z = (abs(xm).^p + abs(ym).^p).^(1/p); 
    surfc(x,y,z)
    hold on
end

hold off

This is my code and this is the plot from the code: enter image description here

How do I limit the plot for only the case where the p-norm is equal to 1?

1

There are 1 best solutions below

0
On

Probably this one will work.

figure;
hold on;

for p=1:5
    [x,y]=p_norm_circle(p,1);
    plot([x, -x], [y -y]);   
end

hold off;
grid;

function [x,y] = p_norm_circle(p, r, step) 

if nargin < 3
    step = 0.01; 
    if nargin < 2
        r = 1;
    end
end

x = -r:step:r;
y = (r^p - abs(x).^p).^(1/p);

end