
The log10() Function in Scilab
Scilab provides the handy log10() function, perfect for calculating the base-10 logarithm of a number.
log10(x)
This function can handle a single number or an array of numbers as the parameter within the round brackets.
The neat thing about this function is that it calculates the base-10 logarithm and spits out a result that matches the size of your initial data.
One thing to keep in mind, though, is that if you place a negative number within the round brackets, the log10() function returns a complex number. If it's zero, you'll get -Inf in return because, as you might know, the logarithm of zero isn't something math can define.
Let's walk through an example to show you how this function can be a helpful tool.
Say you want to calculate the base-10 logarithm of the number 100. Here's how to do it using the log10() function:
log10(100);
The result you'll get is 2, simply because 102 = 100.
2
Now let's venture into calculating the base-10 logarithm of a vector.
First up, you'll want to define an array of values. Let's store them in the variable "v".
v = [1, 10, 100, 1000];
Next, you're going to call up our trusty log10() function to calculate the base-10 logarithm of the array.
log10(v)
What Scilab does here is it works through each element in the array, calculating the base-10 logarithm.
Your final result is another array, but it will be the same size as your original.
[0 1 2 3]
But the log10() function in Scilab isn't just limited to numbers and vectors. You can use it to calculate the base-10 logarithm of a matrix too.
For instance, let's define a 2x2 matrix with four elements. We'll call this variable "M".
M = [1, 100; 10, 1000];
Now, calculate the base-10 logarithm of the matrix with the log10() function.
log10(M)
Scilab will take each element in the matrix, calculate its base-10 logarithm, and provide the results in a neat 2x2 matrix.
[0 2; 1 3]
And there you have it – a quick rundown of the log10() function in Scilab!