3.2. Chapter 2: Intro to Linear Algebra#
Before Class:
Read Chapter 2 in Savov (2020) and take notes
Watch the following videos and take notes:
Compile a list of questions to bring to class
During and After Class:
Take notes (on paper or a tablet computer)
Complete this notebook, submit you answer via Gradescope
Other Resources:
import matplotlib.pyplot as plt
import numpy as np
import scipy.linalg as la
3.2.1. Identify Linear Functions#
P2.1 in Savov (2020)
Classify the following functions as linear or nonlinear?
\(q(x) = x^2\)
\(f(x) = g(h(x))\), where \(g(x) = \sqrt{3}~x\) and \(h(x) = -4 x\)
\(i(x) = \frac{1}{m~x}\)
\(j(x) = \frac{x-a}{x-b}\)
For each function, first determine if it is linear using pencil and paper to test your intuition (do not turn in – honor system). Next, plot the function using Python. Finally, write a few words stating if the function is nonlinear or not and justifying your answer.
# Let's evaluate x from -5 to 5 for ploting
x = np.linspace(-5,5,21)
# function 1
f1 = lambda x : x**2
plt.plot(x, f1(x))
plt.xlabel(r'$x$',fontsize=16)
plt.ylabel(r'$q(x) = x^2$',fontsize=16)
plt.show()
# Add your solution here
Your Answers:
Fill in
Fill in
Fill in
Fill in
3.2.2. Vector Operations#
Given the vectors, \({\bf u} = (1,1,1)\), \({\bf v} = (2,3,1)\), \({\bf w} = (-1,-1,2)\), we will compute several products.
First, let’s plot the vectors in 3D with Python.
# define vectors
u = np.array([1,1,1])
v = np.array([2,3,1])
w = np.array([-1,-1,2])
# Create 3D figure and axes
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Set labels and limits
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
ax.set_xlim([-1,2])
ax.set_ylim([-1,3])
ax.set_zlim([0,2])
# Plot vectors
def plot_vector(vector, color, label):
''' Plot a 3D vector
Arguments:
vector: np array
color: 'r', 'b', 'g', etc.
label: string for legend
'''
assert len(vector) == 3, "Must be a 3D vector"
ax.quiver(0, 0, 0, vector[0], vector[1], vector[2], color=color, arrow_length_ratio=0.1, label=label)
plot_vector(u, 'r', r'${\bf u}$')
plot_vector(v, 'b', r'${\bf v}$')
plot_vector(w, 'g', r'${\bf w}$')
plt.legend(loc='best',ncol=3)
plt.show()
3.2.2.1. Dot Products#
Compute these products by hand (do not turn in – honor system) and with Python.
\({\bf u} \cdot {\bf v}\)
\({\bf u} \cdot {\bf w}\)
\({\bf v} \cdot {\bf w}\)
# Add your solution here
Uses the 3D visualization of these vectors, explain your answers for the three dot products in a few sentences. Hint: what is the geometric interpretation of a dot product?
Your Explanation:
3.2.2.2. Cross Products#
Compute these products by hand (do not turn in – honor system) and with Python.
\({\bf u} \times {\bf v}\)
\({\bf u} \times {\bf w}\)
\({\bf v} \times {\bf w}\)
# Add your solution here
# Add your solution here
# Add your solution here
Uses the 3D visualization of these vectors, explain your answers for the three cross products in a few sentences. Hint: what is the geometric interpretation of a cross product?
Your Answer:
3.2.3. Linear Transformations#
Reference: P2.13 in Savov (2020).
Consider the following three linear transformations that take a two dimensional vector as an input and output a two dimensional vector.
3.2.3.1. Corresponding Matrixes#
Find the 2 x 2 matrices \(\bf A\), \(\bf B\), and \(\bf C\) such that
Hint: Do this on paper first!
# Define your answer as matrices/arrays in numpy.
# Store in variable names A, B, and C
# We'll use this for the next step
# Add your solution here
print("A = \n",A)
print("\nB = \n",B)
print("\nC = \n",C)
3.2.3.2. Matrix Multiplication#
Calculate the matrix products \(\bf A B\) and \(\bf B A\) first on paper and then with Python. (Yes, you should practice doing matrix multiplication by hand at least once.)
# Store your answers in the variables AB and BA
AB = A @ B
# Add your solution here
print("\nAB =\n",AB)
print("\nBA =\n",BA)
Based on your calculations, is matrix multiplication commutative? Explain in a sentence.
Your Answer:
How is \({\bf C}\) related to \({\bf A}\) and \({\bf B}\)? Explain why this makes sense using the word “composite”.
Your Answer:
3.2.4. Atomic Species Balance using Linear Algebra#
Reference: Example 4.7-1 in Elementary Principles of Chemical Process Engineering, Third Edition, Felder and Rousseau (2005)
Methane is burned with air in a continuous steady-state combustion reactor to yield a mixture of carbon monoxide, carbon dioxide, and water. The reactions taking place are:
CH\(_4\) + \(\frac{3}{2}\) O\(_2\) \(\rightarrow\) CO + 2 H\(_2\)O
CH\(_4\) + 2 O\(_2\) \(\rightarrow\) CO\(_2\) + 2 H\(_2\)O
The feed to the reactor contains 7.80 mole% CH\(_4\), 19.4% O\(_2\), and 72.8% N\(_2\). The percentage conversion of methane is 90.0%, and the gas leaving the reactor contains 8 mol CO\(_2\)/mol CO. What is the molar composition of the product stream?
Do the following:
Draw a picture (on paper)
Propose a mathematical model using atomic species balances (on paper)
Perform degree of freedom analysis (on paper)
Convert your model to a linear system (on paper)
Solve with Python (in this notebook)
Print your answer to the screen with a reasonable number of significant digits (in this notebook)
# Add your solution here
3.2.5. Submission#
Please submit two files:
Submit your pencil and paper calculations and pseudocode as requested to Gradescope (one assignment)
Download this notebook as a .ipynb file and submit to to Gradescope (second assignment)
Reminders:
Be sure to upload your pencil and paper calculations and pseudocode to Gradescope as a single PDF for grading.
Review the homework formatting guidelines in the syllabus.
Review the commenting and pseudocode guidlines.