MATLAB Plot unit circle in chebychev metric in MATLAB

AI Thread Summary
The discussion revolves around plotting the unit circle using the Chebyshev metric in MATLAB, aiming to achieve a square representation. The user encounters two main issues: first, the output variable 'y' has an unexpected size of 360x180 instead of the expected 2D coordinates, indicating a potential error in the dimensionality reduction process. Second, the resulting plot resembles that of the Manhattan metric, featuring rounded edges, which is not the intended outcome. The user seeks advice on whether there are alternative functions or syntax to correctly implement the Chebyshev metric transformation. A suggested correction involves using the eigenvalue decomposition method with the cmdscale function to properly derive the coordinates for plotting.
meldraft
Messages
280
Reaction score
2
Ok, so I'm trying to plot the unit circle using the chebyvhev metric, which should give me a square. I am trying this in MATLAB, using the 'pdist' and 'cmdscale' functions. My uber-complex code is the following:

clc;clf;clear all;
boundaryPlot=1.5;

% Euclidean unit circle
for i=1:360
theta(i)=deg2rad(i);
end
zc=[cos(theta)' sin(theta)'];

% Transform to Chebychev metric
x=zc(:,:);
D=pdist(x,'chebychev');
D1=squareform(D);
y=cmdscale(D1);


% Plots
hold on
plot(y(:,1),y(:,2));
axis square;axis([-boundaryPlot boundaryPlot -boundaryPlot boundaryPlot])
plot([-boundaryPlot boundaryPlot],[0 0],'k')
plot([0 0],[-boundaryPlot boundaryPlot],'k')

where the part in bold is the really important part of the code. I have two problems with this. First, the 'y' variable which is supposed to hold the coordinates under the new metric has a size of 360x180. One of these dimensions should have been 2, which is the dimension of the L-p space (p=2).

My second problem is that I get the plot you can see in the attachment, which corresponds to the Manhatan metric, and has rounded edges for some reason.

Has anyone done this calculation before? Is there some other syntax/function I should be using??
 

Attachments

  • untitled.jpg
    untitled.jpg
    10.7 KB · Views: 600
Physics news on Phys.org
The correct syntax should be:clc;clf;clear all;boundaryPlot=1.5;% Euclidean unit circlefor i=1:360 theta(i)=deg2rad(i);endzc=[cos(theta)' sin(theta)'];% Transform to Chebychev metricx=zc(:,:);D=pdist(x,'chebychev');D1=squareform(D);[V,L]=cmdscale(D1);y=V*sqrt(L);% Plotshold onplot(y(:,1),y(:,2));axis square;axis([-boundaryPlot boundaryPlot -boundaryPlot boundaryPlot])plot([-boundaryPlot boundaryPlot],[0 0],'k')plot([0 0],[-boundaryPlot boundaryPlot],'k')
 
Back
Top