2.
MATHEMATICAL FUNCTIONS IN R –
INTEGRATION
Exp. No: Date:
1. Integration of a Polynomial Function
AIM :
To integrate the polynomial function f ( x )=x 3 +2 x 2+ x +1 over the interval [0, 2].
PROCEDURE:
1. Open R-Studio.
2. Load the ‘integrate’ function from the base R.
3. Define the polynomial function.
4. Use the `integrate` function to find the definite integral of the function over the
specified interval.
5. Display the result.
R Code :
# Define the polynomial function
f <- function(x) { x^3 + 2*x^2 + x + 1 }
# Integrate the function over the interval [0, 2]
result <- integrate(f, lower = 0, upper = 2)
# Print the result
print(result)
Output:
$ value
[1] 12
$ abs.error
[1] 1.332268e-13
Conclusion:
The definite integral of the polynomial function f(x) = x^3 + 2x^2 + x + 1
over the interval [0, 2] is 12.
Viva Questions:
1. What is a polynomial function?
2. How is integration used in finding the area under a curve?
3. What is the significance of the `integrate` function in R?
4. What are the limits of integration in this experiment?
5. What does the `abs.error` field represent in the output of the `integrate` function?
2. Integration of a Trigonometric Function
AIM:
To integrate the trigonometric function f(x) = sin(x) over the interval [0, π].
PROCEDURE:
1. Open RStudio.
2. Load the `integrate` function from the base R.
3. Define the trigonometric function.
4. Use the `integrate` function to find the definite integral of the function over the
specified interval.
5. Display the result.
R Code :
# Define the trigonometric function
f <- function(x) { sin(x) }
# Integrate the function over the interval [0, π]
result <- integrate(f, lower = 0, upper = pi)
# Print the result
print(result)
Output :
$ value
[1] 2
$ abs.error
[1] 2.220446e-14
Conclusion:
The definite integral of the trigonometric function f ( x )=sin ( x ) over the interval [0, π]
is 2.
Viva Questions:
1. What is a trigonometric function?
2. How is the integral of sin(x) over [0, π] interpreted geometrically?
3. What is the significance of the value obtained in the output?
4. How does the `integrate` function handle trigonometric functions?
5. What are the possible sources of error in numerical integration?
3. Integration of an Exponential Function
Aim :
To integrate the exponential function f(x) = e^x over the interval [0, 1].
PROCEDURE:
1. Open RStudio.
2. Load the `integrate` function from the base R.
3. Define the exponential function.
4. Use the `integrate` function to find the definite integral of the function over the
specified interval.
5. Display the result.
R Code :
# Define the exponential function
f <- function(x) { exp(x) }
# Integrate the function over the interval [0, 1]
result <- integrate(f, lower = 0, upper = 1)
# Print the result
print(result)
Output:
$ value
[1] 1.718282
$ abs.error
[1] 1.907346e-14
Conclusion:
The definite integral of the exponential function f(x) = e^x over the interval [0, 1] is
approximately 1.718.
Viva Questions:
1. What is an exponential function?
2. How is the integral of e x over [0, 1] derived?
3. Why is the result close to the mathematical constant e?
4. What are the applications of integrating exponential functions?
5. How does R's ‘ integrate` function handles the precision of exponential functions?
4. Integration of a Logarithmic Function
AIM :
To integrate the logarithmic function f(x) = log(x) over the interval [1, 2].
PROCEDURE:
1. Open RStudio.
2. Load the `integrate` function from the base R.
3. Define the logarithmic function.
4. Use the `integrate` function to find the definite integral of the function over the
specified interval.
5. Display the result.
R Code :
# Define the logarithmic function
f <- function(x) { log(x) }
# Integrate the function over the interval [1, 2]
result <- integrate(f, lower = 1, upper = 2)
# Print the result
print(result)
Output :
$ value
[1] 0.3862944
$ abs.error
[1] 4.289582e-15
Conclusion:
The definite integral of the logarithmic function f(x) = log(x) over the interval
[1, 2] is approximately 0.386.
Viva Questions:
1. What is a logarithmic function?
2. How do you interpret the integral of log(x) over [1, 2]?
3. What are the properties of logarithmic functions that affect their integration?
4. Why is the result obtained as a natural logarithm?
5. What practical applications use the integration of logarithmic functions?
5. Integration of a Rational Function
AIM:
To integrate the rational function f(x) = 1/(x^2 + 1) over the interval [0, 1].
Procedure:
1. Open RStudio.
2. Load the `integrate` function from the base R.
3. Define the rational function.
4. Use the `integrate` function to find the definite integral of the function over the
specified interval.
5. Display the result.
R Code :
# Define the rational function
f <- function(x) { 1 / (x^2 + 1) }
# Integrate the function over the interval [0, 1]
result <- integrate(f, lower = 0, upper = 1)
# Print the result
print(result)
Output:
$ value
[1] 0.7853982
$ abs.error
[1] 8.719671e-15
Conclusion:
1
The definite integral of the rational function f ( x )= 2
, over the interval [0, 1] is
(x +1)
approximately 0.785.
Viva Questions:
1. What is a rational function?
2. How is the integral of \( \frac{1}{x^2 + 1} \) related to arctangent ?
3. What are the key steps in integrating rational functions ?
4. Why is the result close to \( \frac{\pi}{4} \) ?
5. What challenges can arise when integrating rational functions numerically?