assignment_1_functions
LMTH 2041 Calculus I Problem Set I: Functions¶
OBJECTIVES
Represent functions with symbols, graphs, tables, and words
Interpret key characteristics of polynomial, logarithmic, and trigonometric functions
Basic Definitions and Plotting¶
Problem 1¶
Define a function $f(x) = x^2$
Create a plot of this function on the domain $x \in [-3, 3]$.
Where does $f(x) = 0$?
Problem 2¶
Define a function $f(x) = x^2 + 2x – 3$
Plot this function on the domain $x \in [-2, 5]$
Where does $f(x) = 0$? How can you be sure?
Problem 3¶
Define a function $h(x) = \frac{1}{x + 4}$
Plot this function on the domain $x \in [-5, -3]$. Is the function defined everywhere? Explain.
Problem 4¶
A company is interested in predicting the amount of revenue it will receive depending on the price it charges for a particular item. Using the data from Table 1.6, the company arrives at the following quadratic function to model revenue $R$ (in thousands of dollars) as a function of price per item $p$:
$$R(p)=p·(−1.04p+26)=−1.04p^2+26p$$for $0\leq x \leq 25$.
Predict the revenue if the company sells the item at a price of $p = \$5$ and $p = \$17$.
Find the zeros of this function and interpret the meaning of the zeros.
Sketch a graph of $R$.
Use the graph to determine the value of $p$ that maximizes revenue. Find the maximum revenue.
Problem 5¶
Starting with the function $f(x) = x^2$ on the domain $x \in [-5, 5]$, describe the effect of the following transformations:
$f(x) = -x^2$
$f(x) = x^2 + 3$
$f(x) = (x – 1)^2$
Your answer should be a single plot with 4 appropriate labels.
Problem 6¶
In the context of artificial neural networks, the rectifier is an activation function defined as the positive part of its argument:
$\displaystyle f(x)=x^{+}=\max(0,x)$
where x is the input to a neuron. This is also known as a ramp function and is analogous to half-wave rectification in electrical engineering. We can rewrite this as a piecewise function:
$$\displaystyle f(x)={\begin{cases}x&{\text{if }}x>0,\\0&{\text{otherwise}}.\end{cases}}$$Define and plot the function on the domain $x \in [-5, 5]$ below.
Problem 7¶
The cost of mailing a letter is a function of the weight of the letter. Suppose the cost of mailing a letter is 49¢ for the first ounce and 21¢ for each additional ounce. Write a piecewise-defined function describing the cost $C$ as a function of the weight $x$ for $0 \leq x \leq 3$, where $C$ is measured in cents and $x$ is measured in ounces.
Problem 8¶
Given the pair of points $A = (-3, 3)$ and $B = (2, 1)$, find:
The slope of the line through the points
An equation of a line through the points
Plot the points and line on the same graph.
Problem 9¶
Total online shopping during the Christmas holidays has increased dramatically during the past 5 years. In 2012 $(t = 0)$, total online holiday sales were $\$42.3$ billion, whereas in 2013 they were $\$48.1$ billion.
Find a linear function $S$ that estimates the total online holiday sales in the year t.
Interpret the slope of the graph of S.
Use your equation to predict the year when online shopping during Christmas will reach $\$60$ billion.
Plot your function and its prediction.
Problem 10¶
A house purchased for $250,000 is expected to be worth twice its purchase price in 18 years.
Find a linear function that models the price P of the house versus the number of years t since the original purchase.
Interpret the slope of the graph of P.
Find the price of the house 15 years from when it was originally purchased.
Problem 11¶
Define and plot the following functions on the domain $x \in [-6, 6]$:
$f(x) = \sin{x}$
$g(x) = \ln(x)$
$h(x) = e ^x$
$j(x) = \sin(x^2)$
Problem 12¶
The number of hours of daylight in a northeast city is modeled by the function
$$N(t) = 12 + 3\sin[\frac{2\pi}{365}(t-79)]$$,
where t is the number of days after January 1.
Find the amplitude and period.
Determine the number of hours of daylight on the longest day of the year.
Determine the number of hours of daylight on the shortest day of the year.
Determine the number of hours of daylight 90 days after January 1.
Sketch the graph of the function for one period starting on January 1.
Functions and Data¶
Problem 13¶
For each of the problems below, you are given a table and graph of a real world dataset. You are asked to choose what kind of function you believe would be a good model of the data; linear, quadratic, exponential, or trigonometric.
The dataset below is on measurements of three different species of iris flowers. We have plotted the petal length on the horizontal axis and petal width on the vertical axis. What kind of function would be a more appropriate model for this data where we input a measure of a petal length, and output a width?
from sklearn.datasets import load_boston, load_diabetes, load_iris
iris = load_iris()
iris = pd.DataFrame(iris.data, columns = iris.feature_names)
iris.head()
sepal length (cm) sepal width (cm) petal length (cm) petal width (cm)
0 5.1 3.5 1.4 0.2
1 4.9 3.0 1.4 0.2
2 4.7 3.2 1.3 0.2
3 4.6 3.1 1.5 0.2
4 5.0 3.6 1.4 0.2
iris.plot(‘petal length (cm)’,’petal width (cm)’, kind = ‘scatter’, title = ‘Petal Length vs. Petal Width’)
Problem 14¶
The data below is from Motor Trend magazine and contains data on different models of cars from multiple manufacturers. We have plotted the measurements for horsepower on the horizontal axis and miles per gallon on the vertical axis. What kind of function do you think would be an appropriate model for this?
import pandas as pd
cars = pd.read_csv(‘https://raw.githubusercontent.com/jfkoehler/calcbook/master/intro/data/mtcars.csv’)
cars.head()
Unnamed: 0 mpg cyl disp hp drat wt qsec vs am gear carb
0 Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4
1 Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4
2 Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1
3 Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1
4 Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2
cars.plot(‘hp’, ‘mpg’, kind = ‘scatter’, title = ‘Horsepower vs. Miles Per Gallon’)
Problem 15¶
The data below comes from the gapminder organization and contains data on countries GDP, Life Expectancy, and Population. We have plotted the data from life expectancy in 2007 on the horizontal axis and GDP on the vertical axis. What kind of relationship would be an appropriate model for this relationship?
gapminder = pd.read_csv(‘https://raw.githubusercontent.com/jfkoehler/calcbook/master/intro/data/gapminder_all.csv’)
gapminder.head()
continent country gdpPercap_1952 gdpPercap_1957 gdpPercap_1962 gdpPercap_1967 gdpPercap_1972 gdpPercap_1977 gdpPercap_1982 gdpPercap_1987 … pop_1962 pop_1967 pop_1972 pop_1977 pop_1982 pop_1987 pop_1992 pop_1997 pop_2002 pop_2007
0 Africa Algeria 2449.008185 3013.976023 2550.816880 3246.991771 4182.663766 4910.416756 5745.160213 5681.358539 … 11000948.0 12760499.0 14760787.0 17152804.0 20033753.0 23254956.0 26298373.0 29072015.0 31287142 33333216
1 Africa Angola 3520.610273 3827.940465 4269.276742 5522.776375 5473.288005 3008.647355 2756.953672 2430.208311 … 4826015.0 5247469.0 5894858.0 6162675.0 7016384.0 7874230.0 8735988.0 9875024.0 10866106 12420476
2 Africa Benin 1062.752200 959.601080 949.499064 1035.831411 1085.796879 1029.161251 1277.897616 1225.856010 … 2151895.0 2427334.0 2761407.0 3168267.0 3641603.0 4243788.0 4981671.0 6066080.0 7026113 8078314
3 Africa Botswana 851.241141 918.232535 983.653976 1214.709294 2263.611114 3214.857818 4551.142150 6205.883850 … 512764.0 553541.0 619351.0 781472.0 970347.0 1151184.0 1342614.0 1536536.0 1630347 1639131
4 Africa Burkina Faso 543.255241 617.183465 722.512021 794.826560 854.735976 743.387037 807.198586 912.063142 … 4919632.0 5127935.0 5433886.0 5889574.0 6634596.0 7586551.0 8878303.0 10352843.0 12251209 14326203
5 rows × 38 columns
import matplotlib.pyplot as plt
gapminder.plot(‘gdpPercap_2007’, ‘lifeExp_2007’, kind = ‘scatter’, title = ‘Life Expectancy vs. GDP’)
plt.ylabel(‘Life Expectancy’)
plt.xlabel(‘GDP Per Capita’);
Problem 16¶
The data below comes from the Central Park weather station for the maximum temperature on each day since 1870. We have plotted the most recent five years of the data where the date is on the horizontal axis and temperature on vertical. What kind of a function would be the right model for this data?
temps = pd.read_csv(‘https://raw.githubusercontent.com/jfkoehler/calculus/master/data/2017018.csv’, usecols=[‘DATE’, ‘TMAX’],
parse_dates = [‘DATE’], index_col=’DATE’)
—————————————————————————
NameError Traceback (most recent call last)
—-> 1 temps = pd.read_csv(‘https://raw.githubusercontent.com/jfkoehler/calculus/master/data/2017018.csv’, usecols=[‘DATE’, ‘TMAX’],
2 parse_dates = [‘DATE’], index_col=’DATE’)
NameError: name ‘pd’ is not defined
temps.head()
1870-01-01 43
1870-01-02 54
1870-01-03 41
1870-01-04 35
1870-01-05 34
temps[‘2015’:].plot()
plt.title(‘Temperatures in Central Park’)
Text(0.5, 1.0, ‘Temperatures in Central Park’)
Using Models¶
For each of the questions below, you are given a model that your team of data scientists have developed based on a given dataset. You are asked three main questions:
Evaluate model at given value.
Compare model prediction to actual value.
Discuss whether the model is a good model for the data and why or why not.
Problem 17: Iris Data¶
Model: petal length = petal width $\times$ .7 or $f(x) = .7x$.
Use the example observation below to compare the offered model to the real data. How close was your prediction? Was this good or bad? Would you recommend this model for other data? Explain.
iris.iloc[3]
sepal length (cm) 4.6
sepal width (cm) 3.1
petal length (cm) 1.5
petal width (cm) 0.2
Name: 3, dtype: float64
Problem 18: Cars¶
Model: mpg = hp/10 or $f(x) = \frac{1}{10} x$ .
Same questions above using the test point below.
cars.iloc[21]
Unnamed: 0 Dodge Challenger
mpg 15.5
cyl 8
disp 318
hp 150
drat 2.76
wt 3.52
qsec 16.87
vs 0
am 0
gear 3
carb 2
Name: 21, dtype: object
Problem 19¶
Plot the function $f(x) = 3^x$ on $x \in [-5, 5]$.
Plot the function $g(x) = \ln(f(x))$ on $x \in [-5, 5]$.
Describe the transformation you observe.