lettura simple

Logarithms in Scilab

Scilab provides the tools to calculate logarithms with any base you need. Let's delve into the various ways you can do this.

The natural logarithm

For the natural logarithm (that is, a logarithm with base e), the log() function comes into play.

log(n)

Say you want to calculate the natural logarithm of 7. All you have to do is type log(7)

log(7)

The resulting natural logarithm of 7 comes out to be approximately 1.94. Why? Because "e" raised to the power of 1.94 is roughly equal to 7.

ans =
1.945910149055313232

Base 10 logarithm

The log10() function allows you to compute logarithms with base 10.

Let's try it out. To calculate the base 10 logarithm of 100, type log10(100).

log10(100)

This gives you a result of 2. Why? Because 10 raised to the power of 2 equals 100.

ans =
2.

Base 2 logarithm

For logarithms with base 2, the log2() function has got you covered.

For instance, to calculate the base 2 logarithm of 16, just type log2(16).

log2(16)

This yields 4, since 2 raised to the power of 4 gives us 16.

ans =
4.

Logarithm in any base

Scilab may not have a built-in function to calculate logarithms for all bases other than "e", 2, or 10, but don't let that stop you.

The change of base formula for logarithms will come to your rescue.

log_b(a) = log_c(a) / log_c(b)

Here, "c" is any base that is positive and not equal to 1.

Consider using the natural logarithm function log() as your base "c".

For instance, to figure out the logarithm of 81 with base 3, type log(81) / log(3)

log(81) / log(3)

The result is 4, since 3 to the power of 4 equals 81.

ans =
4.

Just a friendly reminder that logarithms are defined only for positive numbers. So, please ensure the numbers you're working with are positive.




Report a mistake or post a question




FacebookTwitterLinkedinLinkedin