\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[a4paper, margin=0.75in]{geometry}
% set up hyperlink coloring
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=blue,
filecolor=magenta,
urlcolor=cyan
}
\setlength{\parindent}{0pt} % no indentation
% checkbox list: https://tex.stackexchange.com/questions/247681/how-to-create-checkbox-todo-list
\usepackage{enumitem,amssymb}
\newlist{boxlist}{itemize}{2}
\setlist[boxlist]{label=$\square$}
% code support: listings and fancy verbatim
\usepackage{listings}
\lstset{basicstyle=\ttfamily\footnotesize}
\usepackage{fancyvrb}
\renewcommand{\familydefault}{\sfdefault} % default to sans serif
\usepackage{xcolor}
\newcommand{\code}[1]{\colorbox{lightgray}{\texttt{#1}}}
\newcommand{\sh}[1]{\code{\$ #1}}
\usepackage{graphicx}
%%%%%%%%%%%%%%%%
% python prompt macro
\newcommand{\py}[1]{\code{>{}>{}> #1}}
\begin{document}
\title{Advanced 8\\Python}
\author{EECS 201 Fall 2020}
\date{}
\maketitle
\section*{Submission Instructions}
This assignment is an ``online assignment'' on \href{https://gradescope.com}{Gradescope},
where you will attach your files and answer some questions.
\section{Who needs MATLAB? (5)}
I mentioned in lecture that you could probably replace MATLAB
with Python + NumPy + SciPy + Matplotlib for general purpose use
(unfortunately, MATLAB does have some really nifty tools
in more focused areas that can be hard to replace).
\\\\
For this exercise, we're going to keep it simple since the
SciPy stuff tends to be more domain specific: as much
as I want to throw FFTs at you, I realize that not everyone
has taken EECS 316.
The only package dependencies you'll need are NumPy
(for data types) and Matplotlib (for plotting).
If you don't have those, try installing the \code{pip}
Python package manager and installing those two packages
(or do whatever setup you need to install Python packages
for you particular system). You might also want to look into
``virtual environments'' for Python.
\\\\
Write a script that plots \(y = x^3 -7x^2 + 2x + 2\) for \(-4 \leq x \leq 4\)
with the title ``Who needs MATLAB?'' and saves the figure to a
PNG file called \code{output.png}.
The number of samples you use is up to you, but the figure
should not look jagged from a low sample count.
\begin{itemize}
\item[$\square$] Submit your Python file.
\item[$\square$] Submit the plot you generate.
\item[$\square$] Mention how much previous experience you have had with
MATLAB, NumPy, and Matplotlib in your email.
\end{itemize}
Helpful hints:
\begin{itemize}
\item For those unfamiliar with the general MATLAB workflow for generating plots,
you'll need to generate samples for your X coordinates and samples for your Y coordinates:
these will be matched up by index.\\
For example, your X coordinates could be [-4, -2, 0, 2, 4] and your Y coordinates could
be [16, 4, 0, 4, 16] when plotting \(y = x^2\), albeit with only 5 samples.\\
These samples would then be passed to a plotting function.
\item NumPy comes with its own version of MATLAB's \code{linspace()}:
\href{https://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html}
{\code{numpy.linspace()}}.
This can come in handy for generating your X coordinate samples.
\item If you do this right, given that you have your X coordinate samples,
you only need one line to calculate your Y coordinate samples.
\code{numpy.ndarray}s are your friends!
\item Matplotlib's MATLAB-like plotting function is
\href{https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.pyplot.html}{\code{pyplot.plot}}.
\href{https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.pyplot.html}{\code{pyplot}}
also has a mechanism to save figures.
\end{itemize}
\newpage
\section{Go wild! (5)}
The Python standard library is pretty darn big.
I have no idea what sorts of problems that you all
face in each of your classes or in your life,
but chances are there's some problem that you can
solve with a Python script(s) and using the Python
standard library.
Or perhaps the standard library is missing some feature
(*cough* YAML parsing *cough*) and you need to install
some package.
\\\\
The point of this particular exercise is to go wild
and stretch out your wings with real problems you face:
this is probably the best way to learn and get a feel
for Python.
\\\\
Minimum requirements are to use at least one of the more ``advanced''
modules/packages and have either some sort of file I/O or networking capability.
Modules that provide fairly basic/fundamental things like \code{os}, \code{math}, \code{string} don't count:
feel free to ask if your choice in ``advanced'' module is appropriate.
\textit{Some} examples of modules/packages that I find ``advanced'' enough from the standard library:
\code{csv}, \code{argparse}, \code{curses}, \code{email}, \code{json},
\code{html}, \code{xml} (and friends), \code{http.client}, \code{sqlite3}, \code{tkinter}.
\begin{itemize}
\item[$\square$] Submit your Python file(s) and any additional data files needed.
\item[$\square$] What packages did your script depend on?
\item[$\square$] What is your script for and what does it do?
\end{itemize}
\end{document}