Homework 0¶
This assignment will not be graded. It is provided for you to gauge your prerequisite knowledge for this course. You are not required to turn it in. We recommend that you complete it before the beginning of the semester and no later than after the first week of class (September 8th). This will give you ample time to decide if you are ready to take this course.
Topics¶
Problem 1: Github Setup¶
If you don't already have one, please create a github account: https://github.com.
Note: Please make sure you have a GitHub Pro account. Request for one here: https://education.github.com/discount_requests/new.
Problem 2: Basic Python¶
Sequences and Series¶
Many mathematical and physical constants can be expressed as infinite sums, infinite products, and limits of recursion relationships. In this problem, we will consider representations for two very famous numbers, $\pi$ and $\varphi$.
Series for $\pi$¶
One way to represent $\pi$ is with the infinite sum:
\begin{align*} \frac{\pi^{2}}{6} = \sum_{n=1}^{\infty}{\frac{1}{n^{2}}}. \end{align*}Sequence for $\varphi$¶
The golden ratio $\varphi$ is the positive root of the quadratic equation $x^{2} - x - 1 = 0$. It's exact value is $\varphi = \dfrac{1}{2}\left(1 + \sqrt{5}\right) \approx 1.618033\ldots$.
Interestingly, it can also be expressed as the limit of the ratio of consecutive terms in the Fibonacci sequence. The $n^{\textrm{th}}$ term of the Fibonacci sequence is given by:
\begin{align*} F_{n} = F_{n-1} + F_{n-2}, \quad n > 2 \end{align*}where $F_{1} = F_{2} = 1$ are seed values. For example, the ratio $F_{7} / F_{6} = 1.625$.
In this problem, you will write a function to compute $\pi$ and $\varphi$ from the representations just described.
Part 2.1¶
Write a python
function called numbers
that uses the infinite series
representation to calculate $\pi$ and the ratio of consecutive Fibonacci numbers
to calculate $\varphi$.
Requirements:
- The function should accept two arguments:
- Argument 1: A
string
indicating which number to calculate. The string can be either "pi" or "golden". - Argument 2: An
integer
to specify how many terms to use in the approximation. For example, if the integer is $10$, then the first $10$ terms of the sum for the number in argument 1 will be used.
- Argument 1: A
- Depending on the arguments, the function will calculate either $\pi$ or $\varphi$.
- If the user supplies an unrecognized argument, then the function should fail with an informative error message.
- The function should return a
float
(floating point value) which represents either $\pi$ or $\varphi$.
Hint:
- After $10$ terms you should find $\pi \approx 3.039507\ldots$ and $\varphi \approx 1.617647\ldots$.
Part 2.2¶
Calculate $\pi$ and $\varphi$ using a variety of different terms in the expansion or recursion.
Requirements:
- Create a
python
list
of integers. Each integer represents the number of terms in the series representation or the recursion relation. - The list can be as big as you want, but should ascribe to the following:
- For the $\pi$ expansion, you should use at least $15$ terms and go up to at least $500$.
- For the $\varphi$ recursion, you should use the integers up to $10$. If you go too high, you will get an overflow.
- Iterate over the
list
and calculate $\pi$ and $\varphi$ at each item. - Store the results in a new
list
.
Part 2.3¶
Plot the approximate values of $\pi$ and $\varphi$ as a function of the number of terms.
Requirements:
- Make two separate plots: one for $\pi$ and one for $\varphi$.
- On each figure, plot the true value of $\pi$ and $\varphi$ as a horizontal line.
Hints:
- You may use
numpy
to get the true value. - Your figure might look something like this:
Problem 3: Basic Calculus¶
The final project for this course is to build a software library for automatic differentiation. Please brush up on the following concepts and techniques:
- Derivatives of the usual functions:
- polynomials
- trigonometric functions --- $\sin$, $\cos$, $\tan$, $\sec$, $\csc$
- exponentials --- $e^{x}$, $a^{x}$ ($a$ some constant), $x^y$ (both $x$ and $y$ are variables)
- algebraic functions --- $\sqrt{x}$, $x^{p}$ where $p$ is not an integer, $\ldots$
- Chain rule in 1 dimension
- Chain rule in 2 dimensions
- Chain rule in $n$ dimensions
Important: The chain rule will be reviewed in lecture. The important thing is that you are comfortable with derivatives and the basic procedures.