0
$\begingroup$

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?

$\endgroup$
1
  • $\begingroup$ You can try solving for the set $\{(x,y):\lVert (x,y)\rVert_p=1\}$ and plot that set in 2d for each $p$ $\endgroup$ May 11, 2019 at 17:10

1 Answer 1

0
$\begingroup$

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
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .