negative data ignored when set axis to log
25 views (last 30 days)
Show older comments
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)
g = [-10000:0.1:100000];
f = (ky/kd)*(1./(1+K2*Kx*g.^2))
plot(g,f);
hold all
a = [-10000:0.1:100000];
b = (kx/kd)*(1./(1+K1*Ky*a.^2))
plot(b,a);
set(gca, 'XScale', 'log');
set(gca, 'YScale', 'log');
0 Comments
Answers (1)
Walter Roberson
on 14 Nov 2022
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.
0 Comments
See Also
Categories
Find more on Printing and Saving in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!