Calculus I1. Introduction1.1. What is Calculus?Imagine, you are driving your car. One question, you may ask is what is your average speed during your drive. But during that drive you had different speeds - you were fast on highways, slow at traffic signals. So, there is this experiential notion of 'instantaneous' speed i.e. what is your speed at any given moment?
Calculus is a framework that gives us the tools to help us define a precise notion for that 'instantaneous rate of change'.1.2. Functions1.2.1. What are functions?Essentially, functions are 'mappings'/'rules' that assign each input x in a
domain to exactly one output f(x) in a co-domain.
The easiest way to represent a function is a two column table, of input and
output.
-----------------------------------
| input_domain | output_co_domain |
-----------------------------------
| 1 | 1 |
| 2 | 4 |
| 3 | 9 |
-----------------------------------
But, the problem with the above representation is that it is not very
useful for calculus. For this reason, we represent the same function above
as below, as it gives us
- better abstraction
- a better way to visualize them while coding- the above functions may also be represented as below,1.2.2. What types of functions are there?1.2.2.1. Polynomial Functions1.2.2.1.1. DefinitionA polynomial (over a ring/field `R`) in one variable `x` is an expression of the formwhere `n` is a nonnegative integer, where each coefficient is a real number, and constrained with the requirement that the number of non-zero coefficients be finite.
Another way to think of the above expression is - lets take a finite series of constants a_0, a_1, a_3 .... a_k. Then, each constant is multiplied by `x` to that power of k (i.e. the index of that constant in our series). Sometimes the value of the constant can be 0, and sometimes, it can be non-zero, however the values of k are pre-determined i.e. an index of non-negative integers from 0 to n. The number of constants with a value of 0 can be infinite, however, there is a contraint that the number of constants with a non zero value must be finite.
In a nutshell, the reason why we use the above syntax is simply because it would be too painful to write out the below expanded form all the time.Also, the constraint (that the number of non-zero coefficients be finite) is important, otherwise, we would have a 'power series', not a polynomial. A power series is also a kind of function, but not useful for 99.999% of data science contexts, so we won't cover it in too much detail for now. Without the constraint, the polynomail function becomes a power series function, which is not our focus.1.2.2.1.2. TypesThe type of polynomial is simply the maximum value of `k`, for which the corresponding value of `a_k' is non-zero.1.2.2.1.2.1. Degree 0/ Constant FunctionsA degree-zero polynomial is a constant function, so on a graph it’s a horizontal line at c, parallel to the x-axis.1.2.2.1.2.2. Degree 1/ Linear Polynomial FunctionsA linear function is expressed as below. As you can see, `m` is the value of `a_1`, and 1 is the maximum power of all non-zero coefficients in the polynomial. In other words, `x^2` (like `x^3`, `x^4` .... `x^k`) does exist in the below polynomial, however, its coefficient `a_2` has a value of 0 - which we why we don't write it in the below expression for the sake of simplicity. where the constants `m` and `b` are real numbers:
- `m` is also called the slope (rate of change),
- `b` is also called the y-intercept (i.e. the value when x = 0).
This little `m` is the essence of calculus. And its so easy to visualize in a linear function, because `m` is a constant, which is exactly why linear functions plot as straight lines in a graph. Straigh lines do not bend or curve, which is another way of saying - that they have a fixed slope.Now, if we consider the function y, in context of, an array of 100 evenly spaced values from -5 to 5, along the x axis, we get a straight line plot.1.2.2.1.2.3. Degree 2/ Quadratic Polynomail FunctionsA quadratic polynomial (over a field/ring) is a polynomial of degree 2, i.e.Now, if we consider the function y, in context of, an array of 100 evenly spaced values from -5 to 5, along the x axis, we get a parabola.1.2.2.1.2.4. Degree 3/ Cubic Polynomail FunctionsA cubic polynomial (over a field/ring) is a polynomial of degree 3, i.e.Now, if we consider the function y, in context of, an array of 100 evenly spaced values from -5 to 5, along the x axis, we get a 'cubic curve'.1.2.2.1.2.5. Degree 4/ Quartic Polynomail FunctionsA quartic polynomial (over a field/ring) is a polynomial of degree 4, i.e.Now, if we consider the function y, in context of, an array of 100 evenly spaced values from -5 to 5, along the x axis, we get a 'quartic curve'.1.2.2.1.2.6. Degree 5/ Quintic Polynomail FunctionsA quintic polynomial (over a field/ring) is a polynomial of degree 5, i.e.Now, if we consider the function y, in context of, an array of 100 evenly spaced values from -5 to 5, along the x axis, we get a 'quintic curve'.1.2.2.1.2.7. The 'S' Shape Pattern of Odd Degree PolynomialsAll odd degree polynomials have a consistent S-shaped plot.What's crazy is that even if we use negative value coefficients for all of the non-gihest degree elements of the polynomial, the S curve shape still holds. In even degree polynomials, such a situation would cause the shape to 'wobble' in the middle - as we will see later.Now, if we plot all of the above together, we will see that on an expanded scale, the 'S' curve is more pronounced the greater the odd degree of the polynomial.1.2.2.1.2.8. The "U / W" End-Behavior Pattern of Even Degree PolynomialsAll even degree polynomials share the same end behavior: both ends of the graph go in the same direction.
- If the leading coefficient is positive, both ends go up (a "U-like" end behavior).
- If the leading coefficient is negative, both ends go down (an "∩-like" end behavior).
However, unlike odd-degree polynomials (which tend toward an overall S-shape), even-degree polynomials do not have a single universal middle shape. Their middle can vary widely depending on coefficients.The below example shows positive leading coefficient (both ends up).A typical 4th-degree shape can look like a "W" (more turning points)Higher even degree can be much more "wiggly" in the middle (still both ends up)Now, if we plot all of the above together, you can see the shared even-degree end behavior (both ends rise), while the "middle" differs a lot.Negative leading coefficient causes both ends to point downwards.Even-degree real polynomials have consistent end behavior, but not a single universal middle shape like the odd-degree S. In fact, an even-degree polynomial can have 1, 3, 5, … turning points, so it may look like a U, a W, or much more wiggly—while still sending both ends in the same direction.1.2.2.2. Exponential Functions1.2.2.2.1. DefinitionAn exponential function (in the real numbers) is a function of the formwhere:
- a is a real number called the initial value or amplitude (a ≠ 0),
- b is a real number called the base (usually b > 0 and b ≠ 1),
- x is the exponent (real variable).
The most common and mathematically elegant form uses base e:where:
- e ≈ 2.71828… is the base of the natural logarithm,
- k is the growth rate (or decay rate when k < 0),
- a is the value at x = 0 (sometimes called the initial amount).
Another frequently used form (especially in finance, population models, etc.):where r is the growth rate per unit x (e.g. annual interest rate).Why do we care about e^{kx} instead of just 2^x or 5^x? Because the function f(x) = e^{kx} has the very special property (which we will deep dive into later) i.e. the derivative is proportional to the function itself. This is the defining property of exponential growth/decay and is the reason `e` appears everywhere in science.1.2.2.2.2. Types/ Main Cases1.2.2.2.2.1. ConstantsConstants are a technically valid but trivial exponential functions. This is because when x is 0, exponential functions are pretty much the same as the below expression.In the below example, we get a plot of a line parallel to the x asis but intersecting the y axis at 1, because 7^0 is 1.Notwithstanding the above, all constants can be expressed as exponential functions with x=0, as we can also have1.2.2.2.2.2. Exponential GrowthFor exponential growth, we need an non zero postive value for k, the coefficient of x.For instance,1.2.2.2.2.3. Exponential DecayFor exponential decay, we need an non zero negative value for k, the coefficient of x.For instance,1.2.2.3. Logarithmic Functions1.2.2.3.1. What are log and ln, and why did we come up with them?1.2.2.3.1.1. LogIn the late 1500s, multiplying two 8-digit numbers by hand took a long time and is very error-prone. Doing dozens or hundreds of such operations per day (common in astronomy tables or navigation) was exhausting.
John Napier (Scottish baron, mathematician, and tinkerer) had the breakthrough insight: Turn troublesome multiplication and division into easy addition and subtraction. He spent ~20 years developing this. He defined a function log such that, for the same 'base' x:When you take a log, it is with respect to a base. So, if we simply say log(x) without any base qualifier, we mean base 10.1.2.2.3.1.2. Natural Log/ Ln (pronounced as lawn)The natural log (ln) is useful because it helps us answer a simple question about exponential growth or decay: How long will it take to reach a certain value?
For example, if something grows like 𝑒^{t}, using ln lets us easily solve for the time t needed to reach a specific amount.
When we take a ln, without specifying a base, we mean the log of x with base e.The number e is an irrational mathematical constant approximately equal toIntuitively, it is easy to define e as a 'Taylor series',e is often also represented as the below limit, which comes from the idea of continuous compounding in growth processes.1.2.2.3.1.3. Are bases limited to base 10 and base e?No, generally speaking, we can have any base b of x.1.2.2.3.2. The Power RuleThe power rule states that an exponent inside a logarithm can be moved outside as a multiplier.As discussed above, the entire point of logarithms is to simplify big number multiplication - by converting repeated multiplication into repeated addition.
So the power rule exists because logarithms convert multiplication into addition, and an exponent is just repeated multiplication.This means that,1.2.2.3.3. Converting BasesOne useful thing to review is how we can convert one base to another.
Consider,
- b: the base you want
- c: the base you can compute with
The below formula makes it possible to compute any logarithm using any other base.We can easily prove the above based on first principles, from the very definition of a log.
Let's start with the definition.which means,Now, we take log base c, on both sides.Now, using the power rule of logs,Now, we can re-frame y as,But we also know that,From [1] and [2], we can infer,1.2.2.3.4. Visualizing Logarithmic FunctionsThis plot shows three logarithmic functions with different bases: base 10, base e (the natural logarithm), and base 2.
All logarithmic curves share some important properties. They are only defined for positive values of x, they pass through the point (1,0), and they increase slowly as x grows.
The base determines how quickly the function rises: a smaller base produces a steeper curve. In this plot, log 2 (x) grows the fastest, followed by ln (x), while log 10 (x) log 10 (x) grows the slowest.1.2.2.4. Trigonometric Functions1.2.2.5. Hyperbolic Functions1.2.3. Ratios of Functions