negative data ignored when set axis to log

25 次查看(过去 30 天)
kx = 5000;
Kx = 0.5;
ky = 5000;
Ky = 0.5;
K1 = 0.3;
K2 = 0.3;
kd = 0.7;
Hi, Here is my code below
I am meant to get 3 intersections but it won't plot my negative data when I log the graph
f1 = figure(1)
f1 =
Figure (1) with properties: Number: 1 Name: '' Color: [1 1 1] Position: [671 661 577 433] Units: 'pixels' Show all properties
g = [-10000:0.1:100000];
f = (ky/kd)*(1./(1+K2*Kx*g.^2))
f = 1×1100001
1.0e+03 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
plot(g,f);
hold all
a = [-10000:0.1:100000];
b = (kx/kd)*(1./(1+K1*Ky*a.^2))
b = 1×1100001
1.0e+03 * 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
plot(b,a);
set(gca, 'XScale', 'log');
set(gca, 'YScale', 'log');
Warning: Negative data ignored

回答(1 个)

Walter Roberson
Walter Roberson 2022-11-14
in order to figure out where on the screen to draw the lines when you are using log scale, matlab needs to take log() of the coordinates. If x is negative then log(x) is log(-x) + π*sqrt(-1) which is a complex value. Where should matlab plot items whose log coordinates are complex valued? Should plot() switch to a 3d view, with the third dimension being 0i (real values) and π*1i (complex values)?
Or since for any two positive values, the one with the smaller coordinate is drawn to the left of the one with greater coordinates, then should the negative coordinates be drawn to the left of the nonnegative ones? But -1 is less than 0 so log(-1)would have to be left of log(0)... which is a problem because log(0) is -infinity. So if you have a mix of negative and positive coordinates and log scale then every negative coordinate must be further left than infinitely left of any positive coordinates.
Conclusion: do not use log scale when you have negative coordinates.

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by