0

I'm trying to make a plot with density of the zeros of random quadratic monic polynomials in the complex plane. In fact, I am plotting! But there is just a little detail which is bugging me: the values of the axes are not matching with the points in the plot. Here is my code.

n=2;
p = [1 random('Uniform', -1, 1, [1,n])]
roots(p)
z = zeros(0);
n = 2;
for j=1:10000
    p = [1 random('Uniform', -1, 1, [1,n])];
    R = roots(p);
    z = [ z, R.' ];
end
Re = real(z);
Im = imag(z);
[values, centers] = hist3([Im(:) Re(:)],[1000 1000]);
imagesc(centers{:}, values,[0,10]);
colorbar
axis equal
axis xy
cmap = summer(max(values(:)));
cmap(1:1,:) = 0;
colormap(cmap);

Now here is the plot generated by this code.

plot

You can try this code and check max(Re) and max(Im), which correspond to the maximum values of the real part (x axis) and imaginary part (y axis). I have max(Re) = 1.6076 (it's always something close to 1.5) and max(Im) = 0.9993 (it's always something close to 1). These values doesn't match the plot, which seems to be the opposite.

If I try the scatter function (losing density and all the nice visual), I have the right values. The following command generates the figure below.

scatter(Re(1,:), Im(1,:),'.')

scatter

This clearly shows that the first plot is actually(not rotated as I was thinking first) correct, except for the axes values. I need a help to fix this. Thanks.

PS: The commands to make this plot I got in the answer here. Note the comments there. I explicitly asked for a solution for this problem and got one. The given solution actually worked in some cases but failed in this one, I don't know why.

Community
  • 1
  • 1
Integral
  • 159
  • 2
  • 8

1 Answers1

1

I believe what you are looking for should be:

imagesc(centers{[2,1]}, values,[0,10]);

Incidently, you did not spot the problem in the other post is because the sample images all happen to be more or less square.

Mingjing Zhang
  • 943
  • 5
  • 11
  • Thank you for answering. I made a search and the command **imagesc(min(Re):.00001:max(Re),min(Im):.00001:max(Im), values,[0,10]);** worked just fine. Do you know what is the difference between this command and yours? – Integral Aug 25 '16 at 14:47
  • In image/imagesc, only the x(1)/y(1) and x(end)/y(end) will be used, the rest of these vectors are completely irrelevant. i.e. x might as well just be [min(Re) max(Re)] and you will still get the same result. As long as you put Re as x and Im as y, you are good to go. Using centers is just a way to guarantee you get the same lower/upper bound as hist3 used, without worrying about how they are actually calculated by hist3. – Mingjing Zhang Aug 26 '16 at 04:10