Categories: MathTutorialsVideos

10 Minute Tutorial over Logarithms with a Mix of Javascript


Summary:
This tutorial will provide a simple overview of logarithms.

What are Logarithms?
Logarithms are used to determine the exponent needed to receive a certain value with a particular base.

Example: Log 100 = 2. Since 10^2 = 100.

Here’s a short video explaining logarithms more in-depth with a practical example.

The most common bases used for logarithms are base 10 and E. With base E logarithms normally referred to as the natural logarithm.
In Javascript, the function Math.log returns the natural logarithm of the argument instead of a base 10 logarithm. This can cause some confusion for those unaware of this fact.

Math.log( 100 ) == 2 // returns false
Math.log( 100 ) // returns 4.605170185988092

So how can one use a different base other than E? Well, it simple. All you have to do is take the log of the value that you want, then divide that by the log of the desired based.
Like so.

Math.log( x ) / Math.log( desiredBase );

Here’s a user defined function that does the same operation.

/**
* @function Math.logx
* @purpose: To provide the logarithm for any base desired. Default base is 10.
* @returns a number.
*/
Math.logx = function(x,base) {
    return (Math.log(x)) / (Math.log(base | 10 ));
}

And now, we can calculate log 10 as 2 instead of another number.

Math.log( 100 ) == 2    // returns false
Math.logx( 100 ) == 2   // returns true
Larry Battle

I love to program, and discover new tech. Check out my stackoverflow and github accounts.

Share
Published by
Larry Battle

Recent Posts

What really is Data Science? Told by a Data Scientist

What REALLY is Data Science? Told by a Data Scientist - By Joma Tech

7 years ago

Video: How Water Towers Work

How Water Towers Work - Practical Engineering

7 years ago

Dev Tip: Simple tips to improve code reviews

Writing perfect code is a challenging process. That's where code reviews come in to help…

7 years ago

Video: How AI will change the 3d industry

"The Next Leap: How A.I. will change the 3D industry - Andrew Price - Blender"

7 years ago

Best Software Presentation for 2018

"Captain Disillusion: World's Greatest Blenderer - Live at the Blender Conference 2018 - CaptainDisillusion"

7 years ago

Dev Video: A Few Linux Shell Tips

My 5 Favorite Linux Shell Tricks for SPEEEEEED (and efficiency) - By tutoriaLinux > What's…

7 years ago