## Introduction to Matlab log

Matlab log method can be used to compute the natural logarithm or common logarithm of any number. It can also be used to compute the natural logarithm or common logarithm of an array of numbers or a matrix of numbers. Please keep in mind that a natural logarithm has “e” as its base, where “e” represents Euler’s number and has a value of 2.71828, and a common logarithm has 10 as its base.

**Syntax:**

- A = log (Number) is used to compute the natural logarithm (base “e)” of a number in Matlab. In the case of an array, we will get the natural logarithm of every element in the array.
- A = log10 (Number) is used to compute the common logarithm (base 10) of a number in Matlab. In the case of an array, we will get the common logarithm of every element in the array.

### Examples of Matlab log

Given below shows how to compute the natural logarithm in Matlab using the log method:

#### Example #1

In this example, we will use the log method to compute the natural logarithm of a number.

The step to be followed for this example is:

- Pass the number whose natural logarithm is required as an argument to the log method.

**Code:**

log(4)

[Passing 4 as an argument to the log method as we need its natural logarithm] [Mathematically, the log of 4 to the base “e” is 1.3863]This is how our input and output will look like in the Matlab command window:

**Input:**

**Output:**

As we can see in the output, we have the log of 4 to the base “e” as 1.3863, which is the same as expected by us.

#### Example #2

In this example, we will use the log method to compute the natural logarithm of the elements of an array.

4.5 (7,668 ratings)

View Course

The steps to be followed for this example are:

- Initialize the array.
- Pass the array as an argument to the log method.

**Code:**

A = [3 6 4 8 6 1] [Initializing the array whose natural logarithm is to be computed]

log(A)

[Passing the array as an argument to the log method]This is how our input and output will look like in the Matlab command window:

**Input:**

**Output:**

As we can see in the output, we have obtained the log of all the elements in the array to the base “e”, as expected by us.

#### Example #3

In this example, we will use the log method to compute the natural logarithm of the elements of a matrix.

The steps to be followed for this example are:

- Initialize the matrix.
- Pass the matrix as an argument to the log method.

**Code:**

A = [3 6 4; 8 6 1; 2 1 6] [Initializing the matrix whose natural logarithm is to be computed]

log(A)

[Passing the matrix as an argument to the log method]This is how our input and output will look like in the Matlab command window:

**Input:**

**Output:**

As we can see in the output, we have obtained the log of all the elements in the matrix to the base “e”, as expected by us.

In the above 3 examples, we have computed the natural logarithm of numbers using the log method.

Next, we will compute the common logarithm of numbers using the log10 method.

#### Example #4

In this example, we will use the log10 method to compute the common logarithm of a number.

The step to be followed for this example is:

- Pass the number whose natural logarithm is required as an argument to the log method.

**Code:**

log10(5)

[Passing 5 as an argument to the log10 method as we need its common logarithm] [Mathematically, the log of 5 to the base “10” is 0.6990]This is how our input and output will look like in the Matlab command window:

**Input:**

**Output:**

As we can see in the Output, we have the log of 5 to the base “10” as 0.6990, which is the same as expected by us.

#### Example #5

In this example, we will use the log10 method to compute the common logarithm of the elements of an array.

The steps to be followed for this example are:

- Initialize the array.
- Pass the array as an argument to the log10 method.

**Code:**

A = [4 7 1 3 6 2] [Initializing the array whose common logarithm is to be computed]

log10(A)

[Passing the array as an argument to the log10 method]This is how our input and output will look like in the Matlab command window:

**Input:**

**Output:**

As we can see in the output, we have obtained the log of all the elements in the array to the base “10”, as expected by us.

#### Example #6

In this example, we will use the log10 method to compute the common logarithm of the elements of a matrix.

The steps to be followed for this example are:

- Initialize the matrix.
- Pass the matrix as an argument to the log10 method.

**Code:**

A = [2 5 4; 1 6 3; 6 3 7] [Initializing the matrix whose common logarithm is to be computed]

log10(A)

[Passing the matrix as an argument to the log10 method]This is how our input and output will look like in the Matlab command window:

**Input:**

**Output:**

As we can see in the output, we have obtained the log of all the elements in the matrix to the base “10”, as expected by us.

### Conclusion

The log method can be used in Matlab to compute the logarithm of a number, an array or a matrix. Both natural and common logarithm can be computed. It can be used to compute the logarithm of arrays and matrices as well.

### Recommended Articles

This is a guide to the Matlab log. Here we discuss the introduction to Matlab log along with examples for better understanding. You may also have a look at the following articles to learn more –