This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.

# Calculus in R Contributor:
DataScience+
Visit: DataScience+ Economic data scientist

The article Calculus in R first appeared on DataScience+.

Calculus is a branch of mathematics that involves the study of rates of change. Before calculus was invented, all math was static: It could only help calculate objects that were perfectly still. But the universe is constantly moving and changing. No objects—from the stars in space to subatomic particles or cells in the body—are always at rest. Indeed, just about everything in the universe is constantly moving. Calculus helped to determine how particles, stars, and matter actually move and change in real time.

Calculus is used in a multitude of fields that you wouldn’t ordinarily think would make use of its concepts. Among them are physics, engineering, economics, statistics, and medicine. Calculus is also used in such disparate areas as space travel, as well as determining how medications interact with the body, and even how to build safer structures. You’ll understand why calculus is useful in so many areas if you know a bit about its history as well as what it is designed to do and measure.

Math is one of the key building blocks of data science. If you want to understand what’s going on under the hood in your machine learning work as a data scientist, you’ll need to have a solid grasp of the fundamentals of calculus. While you cannot do a lot of data science with just calculus, the topic is essential for more advanced topics in data science such as machine learning, algorithms, and advanced statistics.

Let’s get started using calculus with R:

Functions in R

Let us first try to do a function and

library(mosaic)
f <- makeFun(m * x + b ~ x, m = 3.5, b = 10)
f(x = 2)
 17

g <- makeFun(A * x * cos(pi * x * y) ~ x + y, A = 3)
g
function (x, y, A = 3)
A * x * cos(pi * x * y)
g(x = 1, y = 2)
 3

Let us try plotting the calculus function

plotFun(A * exp(k * t) * sin(2 * pi * t/P) ~ t + k, t.lim = range(0, 10), k.lim = range(-0.3,0), A = 10, P = 4)

Let us try do do another function in R:

library(manipulate)
plotFun(A * exp(k * t) * sin(2 * pi * t/P) ~ t + k, t.lim = range(0, 10),k.lim = range(-0.3,0), A = 10, P = 4, surface = TRUE)

Let us try do do a third function in R:

plotFun(dt(t, df) ~ t + df, t.lim = range(-3,3), df.lim = range(1,10)) 