\n"," (modified from original notebook by Tri Pham, Yang Liu (HPRC))

- \n","
- arange(start, end, step): return evenly spaced values within a given interval [start, end). step size determine the increment between an element and its predecessor.\n","
- linspace(start, end, num_elements): creates an array of start, start + step, start + 2 * step, ... where step = (end - start) / (num_elements - 1). Note that the end number may be included.\n","
- Due to finite floating point precision, it is difficult to predict the number of elements for arange. Avoid to use arange when step is not an integer.\n","

- \n","
- a.shape = (): the shape of a is actually changed\n","
- a.resize(): the shape of a is actually changed\n","
- a.reshape(): the shape of a does not change\n","

- \n","
- Cluster: clustering algorithms\n","
- Fftpack: fast Fourier Transform algorithms\n","
- Linalg: linear algebra\n","
- Optimize: optimization algorithms\n","
- Sparse: sparse matrices and associated algorithms\n","
- and more ...\n","

- \n","
- Scipy.linalg is preferred unless you do not want the dependency on scipy which requires a Fortran compiler since it is a warpping of Fortran LAPACK using f2py.\n","
- Scipy.linalg is always compiled with BLAS/LAPACK support (faster), while this is optional for numpy.\n","
- All of the BLAS/LAPACK functions are available to use in scipy.\n","

\n"," ```\n"," x + 3y = 10\n"," 2x + 5y = 20\n"," ```"]},{"cell_type":"code","metadata":{"id":"jAFd9eldxCFY"},"source":["A = np.array([\n"," [1, 3], \n"," [2, 5]\n","])\n","\n","b = np.array([\n"," [10], \n"," [20]\n","])\n","\n","print('A =')\n","print(A)\n","print('\\nb =')\n","print(b)\n","print('\\nThe solution of the equations Ax=b is linalg.solve(A, b) =')\n","print(linalg.solve(A, b))"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"pkFPf6wJmVtA"},"source":["### Exercise 6\n","\n","Solve the following equations in the code cell below.\n","\n"," ```\n"," x + 3y + 5z = 10\n"," 2x + 5y + z = 20\n"," 2x + 3y + 8z = 3\n","```"]},{"cell_type":"code","metadata":{"id":"d5ICtkBooMSf"},"source":["# write your code here\n","\n"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"GHtCe274xCFZ"},"source":["### c. Matrix Determinant\n","\n","The determinant of a square matrix A is often denoted |A| and is a quantity often used in linear algebra. \n","Suppose $a_{ij}$ are the elements of the matrix A and let $M_{ij} = |A_{ij}|$ be the determinant of the matrix left by removing the $i^{th}$ row and $j^{th}$ column from A. Then, for any row $i$\n","\n","\n","

- \n","
- A single-precision floating point number is stored as 32 bits\n","
- A double-precision floating point number is stored as 64 bits\n","
- A floating point number normally is not displayed accurately. It is displayed with fewer digits for better readability.\n","
- "]},{"cell_type":"code","metadata":{"id":"imvA5uq_xCFl"},"source":["a = np.arange(7.8, 8.4, 0.05)\n","print(a)\n","print('a[12] is actually', '{0:.55f}'.format(a[12]))"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"OgZr6uqzxCFl"},"source":[" ## 3.2 Error for Comparing Floating Point Numbers\n"," The result may surprise you when two floating point numbers are compared"]},{"cell_type":"code","metadata":{"id":"8ou3ZNnjxCFm"},"source":["print(0.1 + 0.1 + 0.1 == 0.3)\n","print('0.1 is actually stored as', '{0:.55f}'.format(0.1))\n","print('0.3 is actually stored as', '{0:.55f}'.format(0.3))\n","print('0.1 + 0.1 + 0.1 is actually stored as',\n"," '{0:.55f}'.format(0.1 + 0.1 + 0.1))"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"QEWjlc6_xCFm"},"source":[" How to handle issues like this?\n","\n"," This cannot be covered in this course. More study on numeric computation is needed. A simple approach is to claim that 0.1 + 0.1 + 0.1 == 0.3 is True if abs(0.1 + 0.1 + 0.1 - 0.3) < epsilon (a small number, e.g., 0.000001). Numpy provides a function allclose() to check whether two numbers/arrays are close eough to be considered equal."]},{"cell_type":"code","metadata":{"id":"Id1QYYEKxCFn"},"source":["np.allclose(0.1+0.1+0.1, 0.3)"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"3_6iSe7mxCFH"},"source":[" # 4 Matplotlib\n"," Matplotlib is a python plotting library. It\n","
- Produces publiction quality figures.\n","
- Generates plots, histograms, power spectra, bar charts, etc.\n","
- \n","
- The pyplot interface of matplotlib provides a Matlab-like interface.\n","
- Full control of line styles, font properties, etc. are provided via an object oriented inteface or a set of functions.\n","
- Toolkits are availabe: basemap, cartopy, mplot3d, seaboar, ggplot, etc.\n","

- https://www.labri.fr/perso/nrougier/teaching/matplotlib/\n","
- http://nbviewer.jupyter.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-4-Matplotlib.ipynb\n","

- \n","

- \n","