6

I wanted to plot the above function on Matlab so I used the following code

ezplot('-log(x)-log(y)+x+y-2',[-10 10 -10 10]);

However I'm just getting a blank screen. But clearly there is at least the point (1,1) that satisfies the equation. I don't think there is a problem with the plotter settings, as I'm getting graphs for functions like

ezplot('-log(y)+x+y-2',[-10 10 -10 10]); 

I don't have enough rep to embed pictures :)

Ashkan S
  • 10,464
  • 6
  • 51
  • 80
DDDAD
  • 255
  • 3
  • 9

2 Answers2

6

If we use solve on your function, we can see that there are two points where your function is equal to zero. These points are at (1, 1) and (0.3203 + 1.3354i, pi)

syms x y
result = solve(-log(x)-log(y)+x+y-2, x, y);

result.x
% -wrightOmega(log(1/pi) - 2 + pi*(1 - 1i))
%                                         1

result.y
%   pi
%    1

If we look closely at your function, we can see that the values are actually complex

[x,y] = meshgrid(-10:0.01:10, -10:0.01:10);
values = -log(x)-log(y)+x+y-2;

whos values
%  Name           Size                 Bytes  Class     Attributes
%  values      2001x2001            64064016  double    complex

It seems as though in older versions of MATLAB, ezplot handled complex functions by only considering the real component of the data. As such, this would yield the following plot

enter image description here

However, newer versions consider the magnitude of the data and the zeros will only occur when both the real and imaginary components are zero. Of the two points where this is true, only one of these points is real and is able to be plotted; however, the relatively coarse sampling of ezplot isn't able to display that single point.

You could use contourc to determine the location of this point

imagesc(abs(values), 'XData', [-10 10], 'YData', [-10 10]);
axis equal
hold on

cmat = contourc(abs(values), [0 0]);
xvalues = xx(1, cmat(1,2:end));
yvalues = yy(cmat(2,2:end), 1);

plot(xvalues, yvalues, 'r*')

enter image description here

Suever
  • 64,497
  • 14
  • 82
  • 101
3

This is because x = y = 1 is the only solution to the given equation.

Note that the minimum value of x - log(x) is 1 and that happens when x = 1. Obviously, the same is true for y - log(y). So, -log(x)-log(y)+x+y is always greater than 2 except at x = y = 1, where it is exactly equal to 2.

As your equation has only one solution, there is no line on the plot.

To visualize this, let's plot the equation

ezplot('-log(x)-log(y)+x+y-C',[-10 10 -10 10]);

for various values of C.

% choose a set of values between 5 and 2
C = logspace(log10(5), log10(2), 20);

% plot the equation with various values of C
figure
for ic=1:length(C)
    ezplot(sprintf('-log(x)-log(y)+x+y-%f', C(ic)),[0 10 0 10]);
    hold on
end
title('-log(x)-log(y)+x+y-C = 0, for 5 < C < 2');

enter image description here

Note that the largest curve is obtained for C = 5. As the value of C is decreased, the curve also becomes smaller, until at C = 2 it completely vanishes.

aksadv
  • 806
  • 5
  • 6