In order to successfully complete this assignment, you must do the required reading, watch the provided videos, and complete all instructions. The embedded survey form must be entirely filled out and submitted on or before 11:59pm on the day before class. Students must come to class the next day prepared to discuss the material covered in this assignment.
This pre-class assignment is designed to provide a review of the Python packages we will be using in this course.
I think even experienced Python programmers may learn something from the videos. However, feel free to run them at a faster speed and/or skip ahead and review the google doc.
✅ **DO THIS:** Review _Sections 1.4 and 1.5 of the Boyd and Vandenberghe text and answer the questions below.
✅ **QUESTION:** What is the dot product between $u = [ 1, 7, 9, 11]$ and $v = [ 7, 1, 2, 2]$ (Store the information in a variable called uv
)?
Put your answer to the above question here.
from answercheck import checkanswer
checkanswer(uv,'a684eceee76fc522773286a895bc8436');
✅ **QUESTION:** What is the norm of vector $u$ defined above (store this value in a variabled called n
)?
Put your answer to the above question here.
from answercheck import checkanswer
checkanswer(n,'b5b9dc568a9d7d71a6b4c5c95327c6a2');
✅ **QUESTION:** What is the distance between points $u$ and $v$ defined above. (put your answer in a variable named d
)
Put your answer to the above question here.
from answercheck import checkanswer
checkanswer(d,'f09106bd6e8d2573f8bcf0a2073a8a24');
Direct Link to the Youtube video.
from IPython.display import YouTubeVideo
YouTubeVideo("PBlKeuzUf5g",width=640,height=320, cc_load_policy=True)
✅ **DO THIS:** In the following cell, load the math package and run the hypot
function with inputs (3,4).
#Put your answer here
✅ **QUESTION:** What does the hypot
function do?
Put your answer to the above question here.
Direct Link to the Youtube video.
from IPython.display import YouTubeVideo
YouTubeVideo("_hbWtNgstlI",width=640,height=320, cc_load_policy=True)
The Python Numpy library has a matrix
object which can be initialized as follows:
import numpy as np
A = np.matrix([[1,1], [20,25]])
b = np.matrix([[30],[690]])
print("A="+str(A))
print("b="+str(b))
Python can solve equations in the $Ax=b$ format with the numpy.linalg
library. For example:
import numpy as np
x = np.linalg.solve(A, b)
print("x="+str(x))
The numpy.linalg
library is just a subset of the scipy.linalg
library. Oddly you can't load the SciPy library the same way. Instead you can call it as follows:
import scipy.linalg as la
x = la.solve(A, b)
print("X="+str(x))
✅ **DO THIS:** Convert the following system of linear equations to numpy matrices and solve it sing a Python linear algebra solver (Store the solutions in a vector named x
).
$$ 18x+21y = 226$$
$$ 72x-3y = 644$$
##Put your answer to the above question here.
from answercheck import checkanswer
checkanswer.vector(x,'756ca9fa3951fad0e623b2a8315d5fd7');
This one is a little long and reviews some of the information from the last video. However, I really like using images as a way to talk about array and matrix indexing in Numpy
.
Direct Link to the Youtube video.
from IPython.display import YouTubeVideo
YouTubeVideo("XSyiafkKerQ",width=640,height=360, cc_load_policy=True)
%matplotlib inline
import matplotlib.pylab as plt
import numpy as np
import imageio
#from urllib.request import urlopen, urlretrieve
#from scipy.misc import imsave
url = 'https://res.cloudinary.com/miles-extranet-dev/image/upload/ar_16:9,c_fill,w_1000,g_face,q_50/Michigan/migration_photos/G21696/G21696-msubeaumonttower01.jpg'
im = imageio.imread(url)
im[10,10,0] = 255
im[10,10,1] = 255
im[10,10,2] = 255
#Show the image
plt.imshow(im);
im[20,20,:] = 255
plt.imshow(im)
cropped = im[0:50,0:50,:]
plt.imshow(cropped)
cropped = im[50:,350:610,:]
plt.imshow(cropped)
red = im[:,:,0]
plt.imshow(red)
plt.colorbar()
#Note python changed slightly since the making of the video.
# We added the astype funciton to ensure that values are between 0-255
red_only = np.zeros(im.shape).astype(int)
red_only[:,:,0] = red
plt.imshow(red_only)
green_only = np.zeros(im.shape).astype(int)
green_only[:,:,1] = im[:,:,1]
plt.imshow(green_only)
blue_only = np.zeros(im.shape).astype(int)
blue_only[:,:,2] = im[:,:,2]
plt.imshow(blue_only)
✅ **DO THIS:** Modify the following code to set all of the values in the blue channel to zero using only one simple line of indexing code.
no_blue = im.copy()
#####Start your code here #####
#####End of your code here#####
plt.imshow(no_blue)
✅ **QUESTION:** What was the command you use to set all of the values of blue inside no_blue to zero?
Put your answer to the above question here.
Direct Link to the Youtube video.
from IPython.display import YouTubeVideo
YouTubeVideo("qgSa7n_zQ3A",width=640,height=320, cc_load_policy=True)
Since this is a "Matrix Algebra" course, we need to learn how to do 'matrices' in LaTeX. Double click on the following cell to see the LaTeX code to build a matrix:
Basic matrix notation:
$$ \left[ \begin{matrix} 1 & 0 & 4 \\ 0 & 2 & -2 \\ 0 & 1 & 2 \end{matrix} \right] $$Augmented matrix notation:
$$ \left[ \begin{matrix} 1 & 0 & 4 \\ 0 & 2 & -2 \\ 0 & 1 & 2 \end{matrix} ~ \middle\vert ~ \begin{matrix} -10 \\ 3 \\ 1 \end{matrix} \right] $$✅ **DO THIS:** Using LaTeX, create an augmented matrix for the following system of equations:
$$~4x + 2y -7z = 3~$$$$12x ~~~~~~~~+ ~z = 10$$$$-3x -~y + 2z = 30$$Put your LaTeX code here. (Hint: copy and paste from above)
✅ **QUESTION:** In LaTeX, what special characters are used to separate elements inside a row?
Put your answer to the above question here.
Please fill out the form that appears when you run the code below. You must completely fill this out in order to receive credit for the assignment!
If you have trouble with the embedded form, please make sure you log on with your MSU google account at googleapps.msu.edu and then click on the direct link above.
✅ **Assignment-Specific QUESTION:** What is the answers you calculated using Python for $x$ and $y$ to above system of linear equations: $ 18x+21y = 226$ and $ 72x-3y = 644$?
Put your answer to the above question here
✅ **QUESTION:** Summarize what you did in this assignment.
Put your answer to the above question here
✅ **QUESTION:** What questions do you have, if any, about any of the topics discussed in this assignment after working through the jupyter notebook?
Put your answer to the above question here
✅ **QUESTION:** How well do you feel this assignment helped you to achieve a better understanding of the above mentioned topic(s)?
Put your answer to the above question here
✅ **QUESTION:** What was the most challenging part of this assignment for you?
Put your answer to the above question here
✅ **QUESTION:** What was the least challenging part of this assignment for you?
Put your answer to the above question here
✅ **QUESTION:** What kind of additional questions or support, if any, do you feel you need to have a better understanding of the content in this assignment?
Put your answer to the above question here
✅ **QUESTION:** Do you have any further questions or comments about this material, or anything else that's going on in class?
Put your answer to the above question here
✅ **QUESTION:** Approximately how long did this pre-class assignment take?
Put your answer to the above question here
from IPython.display import HTML
HTML(
"""
<iframe
src="https://cmse.msu.edu/cmse314-pc-survey"
width="100%"
height="1000px"
frameborder="0"
marginheight="0"
marginwidth="0">
Loading...
</iframe>
"""
)
To get credits for this assignment, you must fill out and submit the above survey form on or before the assignment due date.
Written by Dr. and Dirk Colbry, Michigan State University
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.