Search code examples
matlabmathplotlogarithmoxyplot

convert quadratic graph to linear using logarithmic scale


I have to draw a quadratic plot (something like y=a*x^2). I wonder is there anyway to find a logarithmical scale for x or y axis to convert this plot to linear form?

for example lets imagine we have a plot like this:
img

I want the final plot be something like this by changing the x or y axis to logarithmical scale. I wonder if this is possible theoretically and the answer is yes how can I find the base value of logarithmical scale.
img


Solution

  • Not sure what the other answers are going on about here - you're right that if you plot a graph like y = ax^2 with logarithmic scaling on both axes, you'll see a straight line. For example, I just ran

    x = 0:0.1:5;
    y = x.^2;
    plot(x, y)
    set(gca, 'xscale', 'log')
    set(gca, 'yscale', 'log')
    

    in Matlab and the result is a straight line. Alternatively, you could take the logarithm of the values and plot them,

    plot(log(x), log(y))
    

    with a linear axis scale. In this case the gradient of the line will be the power of your equation (for a quadratic like this, 2) and the y-intercept will be the constant log(a). This is because

    y = ax^b
    log(y) = log(ax^b)
    log(y) = log(a) + log(x^b)
    log(y) = log(a) + b*log(x).
    

    The base of your logarithm doesn't matter, as long as you know what it is. For these sorts of problems it's common to use the natural logarithm, log in Matlab. log10 or log2 also work.

    Note that these methods only work when x and y are both positive.