Plotting the set of all unit vectors in different norms efficiently?

조회 수: 2 (최근 30일)
David Rannaleet
David Rannaleet 2020년 2월 9일
댓글: David Rannaleet 2020년 2월 9일
I'm trying to plot the set of all unit vectors in different norms and this is the code I've managed to make so far, the issue is that using randn is going to give me lots of redundant points and I'm looking for a cleaner way to plot this without having to rely on randn. I still want the values to be represented as vectors so that I can later apply transformations on them. Any ideas?
function plotUnitNorm(normType)
X = randn(10000,2);
if(strcmp(normType,'inf'))
p_norm = max(abs(X), [], 2);
end
if(strcmp(normType,'1'))
p_norm = sum(abs(X),2);
end
if(strcmp(normType,'2'))
p_norm = sum(abs(X).^2,2).^(1/2);
end
Xn = bsxfun(@times, X, 1./p_norm);
figure(1); scatter(Xn(:, 1), Xn(:, 2), '.');
end

답변 (1개)

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020년 2월 9일
Just make a meshgrid and convert it to a vector
%X = randn(10000,2);
step = 0.02;
[Xi,Yi] = meshgrid(-1:step:1,-1:step:1);
X = [Xi(1:end)',Yi(1:end)'];
if(strcmp(normType,'inf'))
p_norm = max(abs(X), [], 2);
end
...
  댓글 수: 1
David Rannaleet
David Rannaleet 2020년 2월 9일
This gives me 10201 points to plot, when the randn method gives me 10000. So this seems to be even more inefficient plottingwise, I also get blindspots near the corners of the 1-norm and inf-norm using this method.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by