Close Navigation
Learn more about IBKR accounts
Calculus in R

Calculus in R

Posted May 18, 2020
Kristian Larsen

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

f <- makeFun(m * x + b ~ x, m = 3.5, b = 10)
f(x = 2)
[1] 17

g <- makeFun(A * x * cos(pi * x * y) ~ x + y, A = 3)
function (x, y, A = 3)
A * x * cos(pi * x * y)
g(x = 1, y = 2)
[1] 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)

Calculus in R

Let us try do do another function in R:

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))

Calculus in R

Visit to read the full article and download additional R code:

Disclosure: Interactive Brokers

Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.

This material is from DataScience+ and is being posted with its permission. The views expressed in this material are solely those of the author and/or DataScience+ and Interactive Brokers is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

IBKR Campus Newsletters

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.