---
title: 'Homework 1: Scripts and Notebooks'
author: Your Name
output: html_document
---

[Download the starter qmd file here](https://raw.githubusercontent.com/srvanderplas/unl-stat151/main/homework/01-scripts-notebooks.qmd)

## What is the difference between a script and a notebook?

Replace this paragraph with 2-3 sentences describing your understanding of the difference between a script and a notebook. Your answer should be applicable to R or python (so if you discuss python notebooks, you should also discuss the equivalent in R). Use [markdown formatting](https://quarto.org/docs/authoring/markdown-basics.html) as described in [this cheat-sheet](https://github.com/rstudio/cheatsheets/raw/main/rmarkdown.pdf). 

You may want to provide a table or itemized list, and you should use code formatting to indicate file extensions and programming languages.

You can comment this prompt out, so that it does not show up in your document (but is still present in the qmd file) by highlighting the text and hitting Ctrl/Cmd + Shift + C. 


## Playing with Code in Notebooks

The code chunk below defines a logarithmic spiral. 
Using [this reference](https://mathworld.wolfram.com/ArchimedeanSpiral.html), modify the code so that it now plots Fermat's spiral. Use $a = 1$.

```{r}
# Define the angle of the spiral (polar coords)
# go around two full times (2*pi = one revolution)
theta <- seq(0, 4*pi, .01) 
# Define the distance from the origin of the spiral
# Needs to have the same length as theta
r <- theta

# Now define x and y in cartesian coordinates
x <- r * cos(theta)
y <- r * sin(theta)

plot(x, y, type = "l")
```

Can you do the same thing in Python? It may help to know that in Python, to raise something to a power, you use `**` instead of `^`. 


```{python}
import numpy as np
import matplotlib.pyplot as plt

# Define the angle of the spiral (polar coords)
# go around two full times (2*pi = one revolution)
theta = np.arange(0, 4 * np.pi, 0.01)
# Define the distance from the origin of the spiral
# Needs to have the same length as theta 
r = theta

# Now define x and y in cartesian coordinates
x = r * np.cos(theta)
y = r * np.sin(theta)

# Define the axes
fig, ax = plt.subplots()
# Plot the line
ax.plot(x, y)
plt.show()
```
