Given this graph:

enter image description here

We can assume there is a linearity in the semi-curves shown above (note that air line is not my concern here). Obviously, there is a logarithmic relationship for every gas, so for any gas of them:

log(y) = m*log(x) + b     -->     x = 10(log(y)-b)/m

That's how , as far as I understand it, we find x.

However, the thing is, the results I'm getting are not correct. When I searched for very long time, I could find finally someone posted the solution but without any explanation, he used this equation:

x = 10(ln(y)-b)/m

Even though he started finding the slope by using the common logarithm, but to find x he used the natural logarithm as shown above!

The values I'm getting with the absence of any gas is something like: 5.123456 ppm.

However and logically speaking, the expected value should be something like 0.00123 ppm which his little change (from common to natural logarithm) in the final step can do.

Any explanation will be very much appreciated.


Here is some physic facts about the graph:

  • Rs directly related to the gas concentration.
  • R0 is constant for every gas (the concentration in fresh air).
  • The Gas Sensor internally simulates a Voltage Divider.


In other words:

Can we start finding the slope and y-intercept by using the common logarithm because we assumed initially that there is a common logarithmic relationship between x and y, then when we want to find x , we use the base 10 for x but the base e for y? What is the logic behind this? that's basically my question.

MQ2 Datasheet

Application Code

  • 2
    $\begingroup$ It depends on context. Many mathematicians and statisticians will write $\log x$ in place of $\ln x$. Also, maybe the change of base formula ($\log_b x = \frac{\ln x}{\ln b}$) is of importance here. $\endgroup$ Aug 2, 2017 at 19:40
  • 2
    $\begingroup$ There's nothing unexpected about the natural logarithm. What are unexpected are unnatural logarithms... $\endgroup$ Aug 2, 2017 at 19:52
  • 2
    $\begingroup$ Supernatural logarithms are also pretty unexpected. $\endgroup$
    – dxdydz
    Aug 2, 2017 at 20:11
  • $\begingroup$ 5.123456 ppm and 0.00123 ppm are both way off the scale that you're dealing with, so it's unclear why you think one of them is saner than the other. And if those are just numbers you made up to illustrate a point, then you should probably give the actual numbers, as well as an explanation of why you think one is "correct" and the other isn't. Systematically following up on threads in this explanation is likely to reveal the source of the problem. $\endgroup$ Aug 11, 2017 at 17:56
  • $\begingroup$ In fact, if you pick one of the diagonal lines in that plot, extrapolate it, and look at the point on that line has the same value of $R_S/R_O$ as air (i.e. just under 10), then 5.123456 ppm seems much more reasonable than .00123 ppm. Though, again, this is way outside the range that you have data for, so it's unlikely that either of those figures has a close relationship to reality. $\endgroup$ Aug 11, 2017 at 18:29

2 Answers 2


Remember that all logarithms are proportional to each other. In particular $$ \ln(x) = \log_{10}(x)\cdot \ln(10) $$ So whenever you have $$ f(x) = m\log_{10}(x) + b $$ you also have $$ f(x) = m' \ln(x) + b $$ simply by replacing the original constant $m$ by $m'=m/\ln(10)$. And vice versa.

So a linear relationship between $\log_{10} x$ and $\log_{10} y$ is also a linear relationship between $\ln x$ and $\ln y$ -- or indeed between $\ln x$ and $\log_{10} y$ or the other way around -- just by adjusting the coefficients accordingly.

You're right that it looks strange and unmotivated (and may be a typo) to measure one scale by by the base-10 logarithm and the other one by the natural logarithm -- but doing so doesn't actually change the kind of relationship we're speaking of.

Remember also that $$ \log y = m\log x + b $$ gives $$ y = 10^{m\log x+b} = 10^{m\log x}\cdot 10^{mb} = 10^{mb} \cdot x^m $$ So as long as you're using the same kind of logarithms for $x$ and $y$, the coefficient $m$ has a natural interpretation as an exponent.

In particular, for most of your lines $m$ seems to be around $-\frac12$, which suggests that there may be an underlying law of the form $y = \frac{c}{\sqrt x}$, and it may be interesting to plot $y\sqrt x$ instead of just $y$, and look for how the curves differ from being horizontal.

  • $\begingroup$ Thanks for your answer, and plus one though. But unfortunately I still cannot understand it especially because m doesn't equal m' and I should see ln(10) in my equation according to your approach. $\endgroup$
    – user382298
    Aug 2, 2017 at 21:19
  • $\begingroup$ @Yahya: $m'$ is not the same number as $m$, but it is still some constant. You can write the same relationship with either log10 or ln, just by changing the numerical value of $m$. $\endgroup$ Aug 2, 2017 at 21:49
  • $\begingroup$ Exactly. Here some points to take into account: The proportional relation between ln and log is through ln(base) which doesn't exist in the final step x = 10^(ln(y) - b)/m. Why it should exists? because m we calculated from m = log(y1/y) / log(x1/x) is the same exact one we used in the last step here x = 10^(ln(y) - b)/m. I can accept the fact that there is no ln(10) in the final step if it's m' = m / ln(10) either implicitly or explicitly, which in my case I assert that it's the same constant and the same number in both solutions (mine and his). $\endgroup$
    – user382298
    Aug 3, 2017 at 7:00
  • $\begingroup$ In other words, the final equation should contain either x = 10^(ln(y) - b)/m' or x = 10^(ln(y)/ln(10) - b)/m, please note the difference between first m' and second m. Otherwise, why would the result be different.logically speaking, if for example I do x = [(2 +2) *100]/100 there would be no problem, but if I just multiply like x= [(2 +2)*100] there will be then a real change in the value of x which I'm having now in my answers. $\endgroup$
    – user382298
    Aug 3, 2017 at 8:26
  • $\begingroup$ @Yahya: The point is that you can just fold the $\ln 10$ -- which is a constant -- into the $b$ and $m$ coefficients, and get something of the same shape. $\endgroup$ Aug 3, 2017 at 10:45

If you get the values of $m$ and $b$ from a $\log_{10}$ vs $\log_{10}$ graph, then you need a $\log_{10}$ in your equation to make it work. So I think the $\ln$ in his equation is a mistake.

So the question then becomes: why do your calculations not work? (I assume your intuition about the magnitude of the right answer is correct, so you're definitely getting the wrong answer, but I am clueless when it comes to physics so I can't tell.)

The following is pure speculation and may be completely wrong :)

Looking at the graph I can see one possible error one might make. When you calculate $b$, the $y$-intercept, it should be the intercept with the vertical line where $\log x=0$. But your graph starts at $\log x=2$, so if you got $b$ from looking at the intercept with the left-hand side of the graph, that will be the wrong value.

If that's the issue, then the fact that these two mistakes more or less cancel out would just be a fluke. And I don't think there would be anything special about the base $e$ in this sense - after all, his value isn't necessarily exactly right, it's just in the right ballpark, and I expect if you tried the same thing with any base between, say, $2.5$ and $3.5$, you'd still get a plausible answer.

  • $\begingroup$ Thanks for your answer, and plus one though. I am not involving b in my calculation, if you see the last line in the Application Code link mentioned above, you would see a workaround that: x = 10^((log(y) - log(y0))/m) + log(x0) this way we substitute b by log(y) - m.log(x) to avoid this hassle. And I can confirm that his answer at least much much more correct than mine (if not 100% correct and I think it is) $\endgroup$
    – user382298
    Aug 5, 2017 at 8:33

You must log in to answer this question.