EGR 103/Spring 2020/Lab 6
Contents
6.1 Introduction
Some of the problems ask about condition numbers. You will need to read Chapra 11.2 (pp. 292-297) to learn about norms and condition numbers. The summary version is:
- A norm gives you a measure of the size of the entries in a vector or matrix.
- For 1-D arrays (vectors in the text), you need to know how 1, 2, p, and \(\infty\) norms are calculated and be able to calculate them by hand.
np.linalg.norm()
understands these. - For 2-D arrays (matrices in the text), you need to know how 1, f (Frobenius), and \(\infty\) norms are calculated and be able to calculate them by hand. The calculation of a matrix 2-norm by hand is beyond the scope of this class but Python can do it.
np.linalg.norm()
understands these too.
- For 1-D arrays (vectors in the text), you need to know how 1, 2, p, and \(\infty\) norms are calculated and be able to calculate them by hand.
- A condition number of a matrix gives an idea of the sensitivity of the solution relative to the sensitivity of the measurements. The larger the condition number, the more difficult the geometry and thus the more prone to error the results are to measurement errors. The rule of thumb is that your final answer will have as many digits of precision as the number of digits in your measurements minus the base-10 logarithm of the condition number.
- For instance, if you take measurements to 5 significant figures and your system has a condition number of 100, you expectation is that your solution is accurate to \(5-\log_{10}(100)=5-2=3\) digits.
- You generally report ranges of digits if the condition number is not an integer power of 10. For instance, if you know your measurements to 9 figures and your condition number of 485, \(\log_{10}(485)=2.69\) so you will lose between 2 and 3 digits of precision meaning you know your final answers to within 6-7 digits (9 minus 2 or 3).
np.linalg.cond()
can calculate condition numbers andnp.log10()
can calculate log10 of a number.
6.5 Group Auto graded Problems
6.5.1 linsolve
- The returned solution array will have the same dimensions as the array of right-side constants.
- The valid entries for the condition number for a matrix are 1, 2, np.inf, and "fro" where the latter has to be a string.
6.5.2 Chapra 8.10
In general, there are many (correct) ways to re-write the equations in matrix form. For this specific problem, to make the autograder happy, the equations need to be in the matrix in the same order presented in the problem and the unknowns need to be in the same order as presented in the lab handout. Also, given the signs of the constants on the right side of the equation, you can figure out where to move the unknowns in the equations. Note that for this problem the coefficient matrix will be the same every time since the geometry of the system does not change.
6.6 Individual Autograded Problems
6.6.1 Chapra 8.6 (mat_test)
- The autograder will not allow numpy (or anything else!) to be imported
- Your solution will likely have a triple loop. Do some matrix multiplications by hand for small and then larger matrices and figure out what processes you are using. Code those.
- Given that your solution will likely have a triple loop, be careful with your indentation!
- As noted, trying to create an empty list of list of 0 can be problematic since the interior lists are actually pointing to the same information. To visualize the wrong and right ways to make a list of lists of 0, see Python Tutor with examples.
6.6.2 Chapra 8.9 (tanks)
- The code for this will be similar to that from another problem (except for this one you do not have to return the coefficient matrix).
- Once again, I have made some decisions for you in terms of the order of the equations (do the tanks in order), the order of the unknowns (tank order) and the signs of the equations.
6.7 Individual Lab Report
6.7.1 Chapra 8.16
Note that the rotate_2d() function should not do any plotting - in fact, there is no reason to have matplotlib.pyplot in your chapra_08_16.py file! All the plotting will go in other scripts that import your function.
6.7.2 and 6.7.3 Sweeps
Make sure you understand the first two examples at Python:Linear_Algebra#Sweeping_a_Parameter before starting these. You can ignore Python:Linear_Algebra#Multiple_solution_vectors_simultaneously.
6.7.4 Chapra 8.9 Redux
There are a variety of ways to solve this problem; you should incorporate at least a single loop and likely a double loop to do this efficiently. For printing the core of the table, think about what the $$\LaTeX$$ needs to look like first and then use print
, format
, and format specifiers to your example. Remember that to print a \ yuo actually need to give the command \\ in the string. To skip a line, you give the \n command. To keep print
from skipping a line, use the end=""
kwarg.