Single Variable Calculus Chapter 2 2 | AN INTRODUCTION TO SINGLE VARIABLE CALCULUSThis chapter of Single Variable Calculus by Dr JH Klopper is licensed under an Attribution-NonCommercial-NoDerivatives 4.0 International Licence available at http://creativecommons.org/licenses/by-nc-nd/4.0/?ref=chooser-v1 .2.1 IntroductionIn this textbook, we consider calculus in terms of the language of data science. Our first definition in the chapter is then the definition of calculus.Definition 2.1.1 The calculus is the mathematical study of the change in quantities and the accumulation of quantities.The definition is not very helpful. Fortunately, most people have heard the terms differentiation and integration. These are the fundamental topics in calculus. Differentiation concerns itself with change in quantities. Integration concerns itself with the accumulation of quantities.Below, we introduce two use cases for calculus in data science. One for differentiation and one for integration. Do not be concerned if the concepts are unfamiliar to you. They serve merely as motivation for the study of calculus and are covered in courses on statistics. The point is that calculus is crucial to data science.2.2 Calculus in Data ScienceA common task in data science in to create a mathematical model. A simple linear regression model of the form y=β0+β1x, where y is the estimate of a continuous numerical outcome variable, β0 is the intercept estimate, and β1 is the slope estimate describes a line in the plane. From school algebra, we are more familiar with teh equation y=mx+b, where m is the slope of the line (the rise-over-run) and b is the y-intercept (where x=0 which is where the line intersects the vertical axis). In this sense m=β1 and b=β0.In Figure 2.2.1 we see the visual representation of 20 observations. Each observation is a marker on the plot and represents values for two numerical variables. The first variable (on the horizontal axis is the explanatory variable and the second variable in the vertical axis is the outcome variable.ListPlot[{{1,3},{2,4},{3,4},{4,5},{5,6},{3.5,5},{1.4,3.5}},PlotLabel->"Figure 2.2.1",AxesLabel->{"Explanatory variable","Outcome variable"},GridLines->Automatic,ImageSize->Large]Out[]=A linear model is a straight line that can explain the linear association between the explanatory variable and the outcome variable or predict an outcome variable value given an explanatory variable value. We generate the model using the LinearModelFit function below. Do not be concerned with the code here. This function will be covered in the chapter on linear model.In[]:=model=LinearModelFit[{{1,3},{2,4},{3,4},{4,5},{5,6},{3.5,5},{1.4,3.5}},x,x];model["BestFit"]Out[]=2.40159+0.687882xThe mathematical equation is y=0.687882x+2.40159. We have a slope m=0.687882 and an intercept b=2.40159. In terms of writing this as a statistical model we have that β0=2.40159 and β1=0.687882.We see the equation for the model, which we plot in Figure 2.2.2.Show[ListPlot[{{1,3},{2,4},{3,4},{4,5},{5,6},{3.5,5},{1.4,3.5}},PlotLabel->"Figure 2.2.2",AxesLabel->{"Explanatory variable","Outcome variable"},GridLines->Automatic,ImageSize->Large],Plot[2.4+0.69x,{x,1,5}]]Out[]=In the chapter on linear models, we will learn that for every one unit increase in the explanatory variable, we get a corresponding of β1=0.687882 units in the outcome variable. We could also state that of the explanatory variable is for instance 10, then the model estimates an outcome variable value of 0.687882(10)+2.40159≈9.28.There are various techniques to determine the best values for β0 and β1. Once such method creates a loss function containing the variables β0 and β1. A loss function is the difference between the actual value y for a given observation and the predicted value y given specific values for β0 and β1. Starting with arbitrary initial values for β0 and β1, we can use repeated steps involving differentiation, called gradient descent, to minimize the loss function. Gradient descent is a form of optimization and the calculus of differentiation is crucial in determining solutions for models.Integration is used for calculating an area under a curve. The standard normal distribution produces a symmetric bell-shaped curve, centered at 0 and with a variance of 21. The standard normal distribution for a random variable X is a quintessential distribution and is given below using the PDF function.In[]:=PDF[NormalDistribution[]]//TraditionalFormOut[]//TraditionalForm=x.-2x.22πIn Figure 2.2.3 we plot the curve on the interval x∈[-5,5]. The blue shaded area is the area under the curve (between the curve and the horizontal axis).Plot[PDF[NormalDistribution[],x],{x,-5,5},PlotLabel->"Figure 2.2.3",ImageSize->Large,GridLines->Automatic,Filling->Axis]Out[]=Here area refers to probability. We can as what proportion under the curve constitutes a value on the horizontal axis at most -1.96. We use integration in the code cell below to show that the area under the curve from -∞ to -1.96 is about 0.025.In[]:=-1.96∫-∞12π-2x2xOut[]=0.0249979We view this proportion of the area under the curve in Figure 2.1.4. Given that the total area under the curve is 1.0, we can use this information to consider the probability of an event and state that the probability that x (in this case) is at most -1.96 is 2.5%.Show[Plot[PDF[NormalDistribution[],x],{x,-5,5},PlotLabel->"Figure 2.2.4",ImageSize->Large,GridLines->Automatic,PlotLabel->"Figure 2.1.4"],Plot[PDF[NormalDistribution[],x],{x,-5,-1.96},Filling->Axis,PlotRange->{{-5,-1.96},{0,0.45}}]]Out[]=2.3 Mathematics of the infinitesimalIn this textbook we will learn that calculus is the mathematics of the very, very small.Definition 2.3.1An infinitesimal is a quantity that is so small that it cannot be measured.One demonstration of the use of the infinitesimal is to consider a single variable function and to constrain its domain. Our example equation is shown in (1).f(x)=4sin(x)x(1)In Figure 2.3.1 we set the domain x∈[2π,2.2π].PlotSin[4x]x,x,2π,2210π,PlotLabel->"Figure 2.3.1",GridLines->Automatic,ImageSize->LargeOut[]=The output values y=f(x) on the domain fluctuate widely. In Figure 2.3.2 we consider a smaller domain, x∈[2π,2.05π]PlotSin[4x]x,x,2π,4120π,PlotLabel->"Figure 2.2.2",GridLines->Automatic,ImageSize->LargeOut[]=The domain in Figure 2.3.3 is x∈[2π,2.025π].PlotSin[4x]x,x,2π,8140π,PlotLabel->"Figure 2.3.3",GridLines->Automatic,ImageSize->LargeOut[]=The domain is getting smaller and smaller and in Figure 2.3.4 we have x∈[2π,2.001π].PlotSin[4x]x,x,2π,20011000π,PlotLabel->"Figure 2.3.4",GridLines->Automatic,ImageSize->LargeOut[]=Finally, in Figure 2.3.5 we note an almost straight line on the very, very small domain x∈[2π,2.001π].PlotSin[4x]x,x,2π,2000110000π,PlotLabel->"Figure 2.2.5",GridLines->Automatic,ImageSize->LargeOut[]=In calculus we go much further an consider intervals that are infinitely small. In doing so, we can consider instantaneous changes and areas under strangely shaped curves.