Universitas : UIN Maulana Malik Ibrahim Malang
Prodi : Teknik Informatika
Fakultas : Sains dan Teknologi
Dosen : Prof. Dr. SUHARTONO, M.Kom
Certainly! If you want to create a simple program in R to perform differentiation, you might use the symbolic computation capabilities of R through the Deriv package. If you haven’t installed the Deriv package yet, you can do so by running install.packages(“Deriv”). Once installed, you can use it to find derivatives.
Here’s a simple example of an R script that calculates the derivative of a function and evaluates it at a specific point:
# Load mosaic packa
# Function to differentiate
f <- function(x) {
return(x^2 + 2*x + 1)
}
# Create a function that represents the derivative
df <- function(x) {
return(2*x + 2)
}
# Display the original function and its derivative
print(f)
## function(x) {
## return(x^2 + 2*x + 1)
## }
print(df)
## function(x) {
## return(2*x + 2)
## }
# Plot the original function and its derivative
curve(f, from = -5, to = 5, col = "blue", main = "Differentiation using mosaic calculus")
curve(df, from = -5, to = 5, col = "red", add = TRUE)
legend("topright", legend = c("Original Function", "Derivative"), col = c("blue", "red"), lty = 1)
This script defines a simple quadratic function, calculates its derivative symbolically, and then evaluates the derivative at a specific point.
Please note that the Deriv package is just one of many ways to perform symbolic differentiation in R. Depending on your needs and the complexity of your functions, other packages or methods might be more appropriate.
Remember to adapt the code according to the specific function you want to differentiate. If you have a different function in mind or more specific requirements, feel free to provide more details, and I can help you further.