## What is Natural Log MATLAB?

Mathematically, the natural logarithm of a number is defined as the product generated when it’s logarithm is raised to the base e. E is defined as a mathematical constant (2.718281828459).

#### Table of Contents (click to navigate)

## Introduction to the Natural Log Function

Mathematically, the natural logarithm of a number is defined as the product generated when it’s logarithm is raised to the base e. E is defined as a mathematical constant (2.718281828459). The nomenclature for the natural logarithm of x is usually written as ln *x*, log_{e}*x*.[1]. The natural logarithm of x, is the power to which e would have been raised to, in order to generate that original number. All positive real numbers have a natural logarithm function. For example, ln(8) is 2.07944…, because *e*^{2.07944…} = 8.

The graph outlined above, is the graph for the function f(x), where the function is the natural logarithm of the positive numbers on the x-axis. The natural logarithm is also defined as the area under the curve of *y* = 1/*x* from 1 to *a. The a domain is expansive, and the area under the graph is defined as negative when * *a* < 1. Applications of the natural logarithm function are numerous in mathematics and science. In calculations such as chemical kinetics the parameter – the half-life is derived from the use of natural logarithms. Using an example from the chemical sphere, in nature, there are two isotopes of the element carbon that exist in nature. The first isotope is that of carbon twelve, which is prevalent and has an abundance of 98.89%, and the second is carbon thirteen which has an abundance of 1.11%.

Carbon thirteen is the radioactive isotope, and it degrades to form carbon twelve, which is the more stable form of carbon. Via analytical methods such as radiocarbon dating, and the use of the natural logarithmic function, the half-life parameter for the existing carbon thirteen in the sample, is used to back-calculate the age of any sample that is sent for analysis. Many archaeological samples have been assessed in this manner. Mathematical calculations are often used in transformations that facilitate the determination of scientific trends.

## What is Natural Log MATLAB?

With the applications and the mathematical definitions defined, let us delve into the utilization of MATLAB to calculate the natural log of a number or a function. As a code intensive system, the MATLAB software is capable of facilitating the calculation via the syntax:

Y = log(X)

The log(X)function will facilitate the calculation of the natural logarithm of the contents of the domain X. X is usually an array, but can be single number. When defining the function, the user has the ability to either return the calculated natural logs of the entered data, or the data can be collated into a graphical output, in order to identify the data trends. When addressing complex numbers and negative numbers, these are best calculated with the reallog function, due to the resultant output that will be generated by MATLAB if they are used with the natural log function. Complex number with their multiple components, are best operated with the alternate function. Errors may be generated if the natural log function is used on complex number.

## Tutorial: Natural Log MATLAB

With the theory outlined above, let us now delve into the world of calculating natural logarithmic functions in the MATLAB environment. For the purposes of this tutorial, the MATLAB R2019a version of the software will be utilized. The MATLAB R2019a, at the time of writing of this article, is the most recent version of MATLAB. Available either as a downloadable version or an online package, MATLAB remains the most powerful statistical tool that is available today. If you’re a scientist or engineer, this tool is a must in your toolbox. Once you have logged into the MATLAB system, the following fresh Command Page will be open for you to enter your code:

MATLAB R2019a, contains a multitude of functionalities. The ribbons at the top of the command window can be used to facilitate various functions. We will utilize one aspect of the ribbon later down in the tutorial. For the purposes of this initial demonstration, we will be focusing on the Command Window, which is on the bottom right-hand corner of the screen. From the MATLAB Command Window, the majority of the functions will be facilitated by the user. Let’s segway into the first example.

#### EXAMPLE NUMBER ONE

Extracted from the MATLAB Workbook, the objective of this first example is to facilitate the calculation of the Natural Logarithm of a negative number. The question is highlighted as:

**Show that the natural logarithm of -1 is iπ. **

From the syntax above, the Y=log(X) function will be utilized to facilitate the calculation. The number that we want to assess the natural log of is -1. The following code is what we will enter into the MATLAB Command Window.

**log(-1)…(1)**

Once the equation is entered, simply press enter, and the MATLAB system will calculate the function and generate the following output:

**ans = 0.0000 + 3.1416i**

The system output is shown as follows in the image below:

The above calculation is the simplest form of the MATLAB natural log function. Since practice makes perfect, feel free to substitute the (-1) in the function, with different numbers in order to determine the different outputs that can be generated. Single numbers by themselves can simply be calculated in a calculator. Let’s use MATLAB to its optimum, and see how we can generate graphs and plots.

#### EXAMPLE TWO:

MATLAB is a calculating powerhouse, so don’t be afraid to push its limits. MATLAB has the ability to generate a series of graphical output, in formats such as 3-D plots. Get creative! For more complex functions in MATLAB, the following code for a mirrored function can be entered into the MATLAB Command Window. This is an expansion of the log function, but with the range of the domain defined, as well as the associated graph plotted along with the function. Let’s dissect the MATLAB code line by line, so that the details will be clearer. This example is extracted from the MATLAB discussion pool.

**f = @(x) 1+log10(x)…(1)**

This first line of the code is the equation of the function itself. Once the function has been defined, the next step will be for us to determine the range that the function will be calculated over. This leads us to the second line of the code.

**x=[-20:.1:20]…(2)**

The log function as outlined above, is a curve. This question is focused on a series of data ranging from the negative range (with lower limit of -20) all the way to the positive range (with an upper limit of 20). The increments for the process will be increments of 0.1, as indicated by the middle number in the sequence. Once the range has been defined, let us now indicate that a graph should be plotted. This is indicated by the lines of code (3 and 4) below:

**y=f(x)…(3)**

**plot(x,y)…(4)**

**plot(x,y);grid on …(5) **

The final line, is an indicator of the graph details. The user has the ability in MATLAB to determine the output of the graphs, and include features such as labels and the grid. In this instance, we will opt to generate grid lines on the graph. With the codes expanded, let us see what the system will generate. The following is the MATLAB system with the input code:

The MATLAB processes the data, which is an array function. The data range is outlined in increments of 0.1 from the range (-20 to 20). The MATLAB system goes through the process of calculating each of the individual functions, and collates them through Columns, divided into increments of ones, which are further dissected into the increments of 0.1. The following is the graphical output of the plotted data.

The generated data contains all the critical elements that are desired by the user. The graph generated is a beautiful asymptotic curve. Feel free to experiment with other elaborate graphs such as this. This is the point at which mathematics meets art!

## CONCLUSIONS:

MATLAB has the ability to perform a myriad of natural logarithm functions. From the simple to the complex, within the environment, you will be able to generate a series of logarithmic calculations. At the basic level, you can use MATLAB as a calculator, and generate the answers to the desired functions. With the data generated, the user can then proceed to generate more sophisticated information from the generated data. This data can be organized in graphical output. From the generated graph, the data can then be assessed and appropriate trends can be easily identified.

The applications of Natural Logarithms in science and mathematics is numerous. As a user, it will possible for you to use the system to facilitate your calculation needs. Take the time to explore the system, and see how your needs can be facilitated.

#### Reference Articles:

- Natural Logarithm: https://en.wikipedia.org/wiki/Natural_logarithm
- MATLAB Tutorial: https://www.mathworks.com/help/matlab/ref/log.html
- Log Function: https://www.mathworks.com/matlabcentral/answers/282038-how-to-draw-a-log-function