$25
1 Familiarity with Python, Jupyter Notebook, and Numpy/SciPy/Matplotlib
The goal of this problem is to set up the coding environment and go through the basics of Python, NumPy, SciPy, and Matplotlib. For this, you are provided with the “Tutorial-1.ipynb” file that you are required to go through.
Throughout the course, we will be using Python as our choice of programming language and will be Notebooks to demonstrate code. Python is a highlevel, dynamically typed multiparadigm programming language. Python code is often said to be almost like pseudocode, since it allows you to express very powerful ideas in very few lines of code while being very readable.
In the course, we will be assuming a basic familiarity with the Python programming language and will be using ‘python3’, specifically any version 3.6.0. You can check your Python version by typing ‘python –version’. If not already installed in your system, a recommended way to install python is via installing the latest version of ‘anaconda’ or ‘miniconda’ (see – anaconda: https://docs.anaconda.com/anaconda/install miniconda: https: //docs.conda.io/en/latest/miniconda.html. If you have an independent installation or you are using ‘miniconda’, ensure that you have the following basic libraries installed:
1. Python ≥ 3.6.0 (with ‘pip’ – should be automatically present);
2. NumPy (https://numpy.org/install);
3. Scipy (https://www.scipy.org/install.html);
4. Pandas (https://pandas.pydata.org/pandas-docs/stable/getting_started/ install.html);
5. Jupyter Notebook (https://jupyter.org/install);
6. Scikit Learn (https://scikit-learn.org/stable/install.html);
7. seaborn (https://seaborn.pydata.org/installing.html).
We will be informing you along the way whenever more libraries are needed.
We will now briefly talk about notebooks. A Jupyter notebook lets you write and execute Python code locally in your web browser. Jupyter notebooks make it very easy to tinker with code and execute it in bits and pieces; for this reason they are widely used in scientific computing. In order to run the tutorial notebook provided, first ‘cd’ to the directory where the notebook file (“*.ipynb”) is present and then run ‘jupyter notebook’ in your terminal. This should automatically launch a notebook server at ‘http://localhost:8888’. Click on the ‘*.ipynb’ and to finally run the notebook. In order to close a notebook, you need to save and quit the notebook and shutdown the notebook session(s) from the menu. Alternatively, you can press ‘Ctrl+c’ twice in the terminal. For this tutorial, you need to run the “Tutorial-1.ipynb” file.
Optional Reading: You can check out (i) https://numpy.org/doc/1.18/ numpy-user.pdf;(ii) https://sites.engineering.ucsb.edu/~shell/che210d/ numpy.pdf; and (iii) https://github.com/rougier/numpy-tutorial.
2 NumPy exercise
Write the code for the following:
Consider two sets of points p0 and p1 describing a line in a 2-Dimensional (2D) plane. Consider an arbitrary point p in 2D.
1. Compute the orthogonal distance between the point p and the the line segment joining the points p0 and p1.
2. Plot the line segment joining the points p0 and p1, the point p and the orthogonal distance between the point and the line segment.
3 Linear Algebra
1. Suppose that u ∈ R3 is a vector which lies in the first quadrant of the xy-plane and has a length 3 and that v ∈ R3 is a vector that lies along the positive z-axis and has a length 5. Then,
(a) ||u × v|| =
(b) The x-coordinate of u × v is0 (choose <, , or =) ;
(c) The y-coordinate of u × v is0 (choose <, , or =) ;
(d) The z-coordinate of u × v is0 (choose <, , or =) ;
√
2. Suppose that u and v √are vectors in R7, both of length 2 2, and the
length of u − v is also 2 2. Then,
(a) ||u + v|| = ; (b) The angle between u and v is .
3. Consider the following matrix where a is a real number.
(a) For what values of a will a row interchange will be required during Gaussian elimination process? Answer: a = .
(b) For what values of a is the matrix singular? Answer: a = .