Building an implicit function x + y - log (x) - log (y) -2 = 0 on MATLAB

I wanted to build 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 just get a blank screen. But, obviously, there exists at least a point (1,1) that satisfies the equation. I don’t think there are problems with plotter settings, since I get graphs for functions like

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

I don't have enough reputation for embedding images :)

+6
source share
2 answers

This is due to the fact that x = y = 1 is the only solution to this equation.

Note that the minimum value of x - log(x) is 1, and this happens when x = 1 . Obviously, the same is true for y - log(y) . Thus, -log(x)-log(y)+x+y always greater than 2, with the exception of x = y = 1 , where it is exactly 2.

Since your equation has only one solution, there is no line on the graph.

To visualize this, let's build an 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+yC = 0, for 5 < C < 2'); 

enter image description here

Note that the largest curve is obtained for C = 5 . As C decreases, the curve also becomes smaller until it reaches C = 2 .

+3
source

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

 syms xy 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 will 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 that in older versions of MATLAB ezplot complex functions are processed, considering only the real data component. Thus, it will give the following graph

enter image description here

However, newer versions take into account the magnitude of the data, and zeros will occur only when both the real and imaginary components are equal to zero. Of the two points where this is true, only one of these points is real and can be built; however, a relatively coarse selection of ezplot cannot display this single point.

You can use contourc to locate 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

+6
source

Source: https://habr.com/ru/post/1014747/


All Articles