Plotting a line using one point and a slope in the loglog scale

6 views (last 30 days)
I am trying to plot a line in the loglog scale using a given point and a slope but the graph(attached) that I am getting is not correct. This is what I have tha gives me the graph attached.
x = (25081:1000:10000000);
m = -3.62;
x1 = log(25081);
y1 = log(3.046*10^-16);
y = m*(x-x1)+ y1;
loglog(x, y)

Accepted Answer

VBBV
VBBV on 29 Nov 2022
x = (25081:1000:10000000);
m = -3.62;
x1 = 25081; % use coordninate
y1 = 3.046e-16;
y = m*(x-x1)+ y1
y = 1×9975
1.0e+07 * 0.0000 -0.0004 -0.0007 -0.0011 -0.0014 -0.0018 -0.0022 -0.0025 -0.0029 -0.0033 -0.0036 -0.0040 -0.0043 -0.0047 -0.0051 -0.0054 -0.0058 -0.0062 -0.0065 -0.0069 -0.0072 -0.0076 -0.0080 -0.0083 -0.0087 -0.0091 -0.0094 -0.0098 -0.0101 -0.0105
loglog(x, abs(y)) % log of negative number are not defined
  1 Comment
VBBV
VBBV on 29 Nov 2022
Since the slope is negative , the y vector will be negative. instead you can use semilogx
x = (25081:1000:10000000);
m = -3.62;
x1 = 25081; % use coordninate
y1 = 3.046e-16;
y = m*(x-x1)+ y1
y = 1×9975
1.0e+07 * 0.0000 -0.0004 -0.0007 -0.0011 -0.0014 -0.0018 -0.0022 -0.0025 -0.0029 -0.0033 -0.0036 -0.0040 -0.0043 -0.0047 -0.0051 -0.0054 -0.0058 -0.0062 -0.0065 -0.0069 -0.0072 -0.0076 -0.0080 -0.0083 -0.0087 -0.0091 -0.0094 -0.0098 -0.0101 -0.0105
semilogx(x, y) % considering the slope direction

Sign in to comment.

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!