In this article, we will show you the **exp() function in R **and provide some knowledge of this function in mathematics. Let’s read it now.

## What is the exp() function in R?

The exp() function calculates the natural exponential value of a number. The formula is f(x) = e^x with e=**2.17128128**.

**Syntax: **

`exp(number)`

**Parameter:**

**number:**An integer, float, or complex number.

## How to use the exp() function?

In mathematics, calculating the natural exponential value is very popular and essential because the function is widely applied in many fields. We will take three examples to show how to use the function to find the result when using the function with an integer, a float number, and a complex number. There will be a little difficulty with mathematics, so read carefully.

**Use the exp() function to calculate the natural exponential value of an integer**

Calculating the natural exponential value of an integer is the most popular in education. In this part, we will use the function to find the result of e^x where x is an integer.

**Code:**

# Declare an integer intNumber = 3 # Calculate the natural exponential of the number result = exp(intNumber) # Print the result cat("The natural exponential of", intNumber, "is", result)

**Result:**

`The natural exponential of 3 is 20.08554`

**Use the exp() function to calculate the natural exponential value of a float**

In this example, we will use the exp() function to get the result of the natural exponential value of a float.

**Code:**

# Declare a float number floatNum = 2.26 # Calculate the natural exponential of the number result = exp(floatNum) # Print the result cat("The natural exponential of", floatNum, "is", result)

**Result:**

`The natural exponential of 2.26 is 9.583089`

**Use the exp() function to calculate the natural exponential value of a complex number**

A complex number z is defined as a + bi. This part is much more difficult to understand, and we will look at the formula in the mathematics field before diving deeply into implementing the code.

`e^(a+bi) = e^a x e^(bi) and e^(bi)= cos(b) + isin(a)`

So `e^(a+bi) = e^(a) x cos(b) + e^(a) x sin(a)i`

Apply the function, `e^(2+2i) = e^2 x cos(2) +e^(2) x sin(2)i = -3.074 = 6.71i`

Let’s use the exp() function to calculate and compare the result.

**Code:**

# Declare a complex number complexNum = 2 + 2i # Calculate the natural exponential of the number result = exp(complexNum) # Print the result cat("The natural exponential of", complexNum, "is", result)

**Result:**

`The natural exponential of 2+2i is -3.074932+6.71885i`

## Summary

In summary, the **exp() function** calculates the natural exponential value of a number with the formula f(x) = e^x, with x can be an integer, float, or even a complex number. We hope this article is helpful.

**Maybe you are interested**:

- Use Average Function In R On Different Data Sources
- How To Curve Function In R To Create Plots
- Aes Function In R: Construct Aesthetic Mappings

My name is Robert Collier. I graduated in IT at HUST university. My interest is learning programming languages; my strengths are Python, C, C++, and Machine Learning/Deep Learning/NLP. I will share all the knowledge I have through my articles. Hope you like them.

**Name of the university: **HUST

**Major**: IT

**Programming Languages**: Python, C, C++, Machine Learning/Deep Learning/NLP