Logarithms between 0 and 1 and ratios

2 views (last 30 days)
Hello
I have to divide two things. They are really small, so I did log of both of them and then divided. Now, the thing is that without log, the ratio is less than 1, while, with the log, the ratio is larger than 1. I know this is due to the fact that the smallest number returns a smaller log, which when dividing and cancelling signs, becomes larger. How could I avoid the 'inconsistence' between ratios? I mean, I want to have the same result (ratio less or more than 1) independently of how I do it.
Thank you.
  1 Comment
Pawel Jastrzebski
Pawel Jastrzebski on 19 Jul 2018
What is "two things"? What does it mean "really small"? Your whole description is so vague and the description I doubt anyone will be able to catch up with your problem, not to mention coming up with some help. Can you attach some examples of the data you're working on? And the code that you've developed so far that presents the transformation you've described (logging, dividing, cancelling)? This way we can have a look at the problem, not the description of it...

Sign in to comment.

Accepted Answer

Dimitris Kalogiros
Dimitris Kalogiros on 19 Jul 2018
Edited: Dimitris Kalogiros on 19 Jul 2018
Hi Juan
Suppose you have to divide two very small numbers x, y. And assume that 0<x<<0 and also 0<y<<0. A mathematical correct method is to exploit the following indentity :
x/y = exp( log( x/y ) ) = exp( log(x) - log(y) )
So, difference of logarithms is a metric of the ratio.
On the other hand, if you want to calculate the ratio, you must use logarithm difference as argunent to exp function.
  1 Comment
Juan Gambetta
Juan Gambetta on 19 Jul 2018
Edited: Juan Gambetta on 19 Jul 2018
Thank you, the difference of the logs is a great idea. Very elegant.

Sign in to comment.

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Tags

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!