# Miniproject 1
## Overview
In this miniproject you will learn about *Markov chains* and use them to make predictions about long term trends in population growth and US voter activity.
**Prerequisites**: You'll need to know how to multiply a matrix times a vector, both by hand and using SymPy.
**Initial deadline**: *Sunday, February 5 at 11:59pm ET.*. This is the deadline for all *first* drafts of your solution. If you turn in a good-faith effort at a complete and correct solution by this date, you may continue to revise and resubmit as needed with no additional deadlines, until the final deadline of 11:59pm ET Sunday April 16. However, no *first* drafts will be accepted after the initial deadline.
## Background
Complete the following before beginning this miniproject. These are not to be turned in! But you won't get far on the assignment without doing them.
- Read Section 1.3.1 (Markov chains: An application of matrix-vector multiplication) on pages 26--28 in the textbook and work through the examples shown.
- If needed, [watch the tutorial video where I walk through Example 1.3.3](https://gvsu.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=97c3c6f8-d68e-461c-ac95-af72010dec46). This also shows how to use SymPy to do some of the math.
- Practice with SymPy by using it to work Exercises 1-4 on page 29.
## Assignment
1. (Exercise 26) Suppose that for a large population that stays relatively constant (that is, there are no population explosions or mass migrations), people are classified as living in urban, suburban, or rural settings. Moreover, assume that the probabilities of the various possible transitions are given by the following rule:
| Future location / current location | U (%) | S (%) | R (%) |
| ---------------------------------- | ----- | ----- | ----- |
| Urban | 92 | 3 | 2 |
| Suburban | 7 | 96 | 10 |
| Rural | 1 | 1 | 88 |
(a) In plain English, what does the "10" in the table above mean?
(b) Let $U_n$, $S_n$, and $R_n$ represent the populations of people in urban, suburban, and rural areas respectively in year $n$ Write an equation that expresses $U_{n+1}$ in terms of $U_n$, $S_n$, and $R_n$. Then do the same for $S_{n+1}$ and $R_{n+1}$.
(c) Take the three equations from part (b) and convert them into a transition matrix $M$. Is this a stochastic matrix? Explain.
(d) Assume that the entire population is 250 million people, initially distributed into 100 million urban, 100 million suburban, and 50 million rural. With this assumption, predict the population distribution after 5, 10, and 25 years.
(e) As the number of years grows larger and larger, what appears to be happening to the population distribution?
2. Three major political parties in the United States are the Democratic, Republican, and Libertarian parties. Let $D_k$, $R_k$, and $L_k$ represent the percentage of voters voting for the Democratic, Republican, and Libertarian parties in election $k$. Over time, people sometimes switch their party affiliation when they vote. The
diagram below shows a possible system of voter affiliation change:
![](https://i.imgur.com/tXvhRF2.png)
In this model, 70% of voters stay with the same party from one election to the next. But, for example, 15% of voters who vote Republican in one election will switch to vote Libertarian in the next.
(a) Write expressions for $D_{k+1}$, $R_{k+1}$, and $L_{k+1}$ in terms of $D_k$, $R_k$, and $L_k$ and briefly explain your reasoning.
(b) If we write $\mathbf{x}_k = \begin{bmatrix} D_k \\ R_k \\ L_k \end{bmatrix}$, find the matrix $A$ such that $\mathbf{x}_{k+1} = A \mathbf{x}_k$.
(c) Explain why $A$ is a stochastic matrix.
(d) Suppose that, initially, 45% of voters vote Democratic, 43% vote Republican, and the remainder vote Libertarian. Form the vector $\mathbf{x}_0$. Then, find $\mathbf{x}_1$, the percentage of voters who vote for the three parties in the next election. Summarize your results in a single sentence.
(e) Find $\mathbf{x}_4$, $\mathbf{x}_{8}$, and $\mathbf{x}_{12}$. Over time, what percentage of the vote should each party expect to get in an election? Explain your reasoning.
## Submission and Grading
### Formatting and special items for grading
Please review the section on Miniprojects in the document [Standards For Student Work in MTH 302](https://github.com/RobertTalbert/linalg-diffeq/blob/main/course-docs/standards-for-student-work.md#standards-for-miniprojects) before attempting to write up your submission. Note that *all* Miniprojects:
- **Must be typewritten**. If any portion of the submission has handwritten work or drawings, it will be marked *Incomplete* and returned without further comment.
- **Must represent a good-faith effort at a complete, correct, clearly communicated, and professionally presented solution.** Omissions, partial work, work that is poorly organized or sloppily presented, or work that has numerous errors will be marked *Incomplete* and returned without further comment.
- **Must include clear verbal explanations of your work when indicated, not just math or code**. You can tell when verbal explanations are required because the problems say something like "Explain your reasoning".
Your work here is being evaluated *partially* on whether your math and code are correct; but just as much on whether your reasoning is correct and clearly expressed. Make sure to pay close attention to both.
Miniproject 1 in particular **must be done in a Jupyter notebook using SymPy to carry out all mathematical calculations**. [A sample notebook, demonstrating the solution to a Calculus problem, can be found here](https://github.com/RobertTalbert/linalg-diffeq/blob/main/tutorials/Example_of_solution_in_a_notebook.ipynb). Study this first before writing up your work.
It's likely that writing up your Miniproject work in a Jupyter notebook will become standard practice for later Miniprojects.
### How to submit
You will submit your work on Blackboard in the *Miniproject 1* folder under *Assignments > Miniprojects*. But you will *not* upload a PDF for Miniprojects. Instead you will **share a link that allows me (Talbert) to comment on your work**. [As explained in one of the Jupyter and Colab tutorials](https://gvsu.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=ef5c0e24-5c1d-437f-be05-af730108b6d8), the process goes like this:
1. In the notebook, click "Share" in the upper right.
2. **Do not share with me by entering my email.** Instead, go to *General Access*, and in the pulldown menu select "Anyone with the link", then set the permissions to "Commenter".
3. Then click "Copy Link".
4. **On Blackboard**, go to the *Assignments* area, then *Miniprojects*. Select Miniproject 1.
5. Under **Assignment Submission**, where it says *Text Submission*, click "Write Submission".
6. **Paste the link to your notebook in the text area that appears.**
7. Then click "Submit" to submit your work.
I will then evaluate your work using the link. Specific comments will be left on the notebook itself. General comments will be left on Blackboard.

Initial due date: Sunday, April 9 at 11:59pm ET Overview This miniproject introduces a version of Euler's Method as a numerical solution technique for systems. Prerequisites: You will need to be comfortable with using Euler's method for single differential equations. You'll also benefit from some familiarity with spreadsheets or Python in order to automate the calculations. Background This tutorial gives you the background you need for this assignment. Please read it and make sure you understand the concepts and the example: https://github.com/RobertTalbert/linalg-diffeq/blob/main/assignments/Euler's_Method_for_Systems.ipynb

3/22/2023Initial due date: Sunday, March 26 at 11:59pm ET Overview Eigenvalues of a matrix are incredibly useful and important for many applications. (Some of these applications are in Miniprojects 1-3.) But computing eigenvalues of a matrix, even of relatively small size, can be difficult or impossible to do exactly. So we need numerical approximation methods for most practical uses of eigenvalues. This miniproject will teach you one such method. Prerequisites: You'll need to know what an eigenvalue and eigenvector for a matrix are, and how to find these using SymPy. You'll also need to know how to multiply matrices and vectors. Background Complete the following warmup exercises first. These don't go in your writeup. They are just here to teach you some terminology you'll need in the main assignment.

3/3/2023Initial due date: Sunday, March 12 at 11:59pm ET Overview In this miniproject, you'll apply concepts from linear algebra to study discrete dynamical systems. These are related to the idea of Markov chains that was the subject of Miniproject 1 and are the linear algebra analogue of systems of differential equations which we will study later. Prerequisites: You'll need to know what an eigenvalue and eigenvector for a matrix are, and how to find these using SymPy. This miniproject also requires some knowledge of matrix-vector multiplication. Background Complete the following before beginning this miniproject. These are not part of your writeup, but you'll need the knowledge before you can understand the tasks in the assignment.

2/21/2023Initial due date: Sunday, February 26 at 11:59pm ET Overview In this miniproject, you'll explore the concept of matrix transformations and use matrix transformations in $\mathbb{R}^3$ to create a very simple computer animation --- and see how linear algebra is used to make more complex animations happen. Prerequisites: You'll need to know how to multiply a $3 \times 3$ matrix to a $3 \times 1$ vector using SymPy, as well as what some of our recent theorems about matrices and invertibility say. Also, you'll need to do a bit of background learning using the video mentioned below. Background Complete the following before beginning this miniproject. These are not part of your writeup, but you'll need the knowledge before you can understand the tasks in the assignment.

2/9/2023
Published on ** HackMD**