Theory (40 points/10 points each) 1. We have three vectors, v1=(1, 2, 5), v2=(4, 2, 7), and v3=(6, 6, 17). Please check that these vectors are linearly independent or not. If these three vectors are...

1 answer below »
Please see instructions for this assignment in the word doc. You need to do both theory and practice, you can use Jupyter Notebook.


Theory (40 points/10 points each) 1. We have three vectors, v1=(1, 2, 5), v2=(4, 2, 7), and v3=(6, 6, 17). Please check that these vectors are linearly independent or not. If these three vectors are linearly dependent, present v3 as a linear combination of v1 and v2. (you can use python code for checking linear dependency). 2. We have two vectors, v1=(2, 4, 1) and v2=(3, -1, -3). Please check that these vectors are orthogonal or not. If they are not orthogonal, please find the projected vector of v1 onto v2 (Pv2(v1)). (Do not use a python code). 3. We have a matrix, . Using rank, please check that this matrix is a singular matrix or not. If this is a singular matrix, find coefficients a and b, which satisfies this equation with 1st row (v1) and 2nd row (v2) of the matrix: av1 + bv2 = 0. (you can use a python code) 4. We have a matrix, . Calculate the inverse matrix and check this is a singular matrix or not. (you can use a python code) Practice (60 points) 1. Least-squares (30 points) (U: uniform distribution, N: normal distribution) a. Make 1,000 noise data by x ~ U[0, 1], y = 2+ 3x + 0.1e (e ~N(0,1)). (10 points) b. Do least-squares method by solving linear equation (refer to our lecture slide) and find an approximated linear function. (10 points) c. Draw scatter plot for (x,y) and the approximated linear function on the same graph. (10 points) 2. Singular Value Decomposition (30 points) (U: uniform distribution, N: normal distribution a. Using same data (x,y) in practice problem #1. b. Do SVD (refer to our lecture slide) and reduce a noise. (10 points) c. Do least-squares method for denoised data from b and find an approximated linear function (10 points) d. Draw scatter plot for denoised (x,y) and the approximated linear function on the same graph. (10 points)
Answered Same DayOct 13, 2021

Answer To: Theory (40 points/10 points each) 1. We have three vectors, v1=(1, 2, 5), v2=(4, 2, 7), and v3=(6,...

Abr Writing answered on Oct 15 2021
149 Votes
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Importing the necessary libraries"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import sys\n",
"import matplotlib.pyplot as plt\n",
"import scipy.optimize as optimization"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Theory"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Linear Independence"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[2.13798760e+01 1.70320365e+00 1.17478406e-15]\n",
"3\n"
]
}
],
"source": [
"v1 = [1,2,5]\n",
"v2 = [4,2,7]\n",
"v3 = [6,6,17]\n",
"\n",
"A = np.row_stack([v1, v2, v3])\n",
"\n",
"# MATLAB definition of tolerance\n",
"eps = np.finfo(np.linalg.norm(A).dtype).eps\n",
"TOLERANCE = max(eps * np.array(A.shape))\n",
"\n",
"U, s, V = np.linalg.svd(A)\n",
"print(s)\n",
"print(np.sum(s > TOLERANCE))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2\n"
]
}
],
"source": [
"TOLERANCE = 1e-14\n",
"print(np.sum(s > TOLERANCE))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can see if you choose too small a T
OLERANCE, nothing looks like zero. T he finding with TOLERANCE=1e-14 implies the rows are not linearly independent. Let's see that one row can be represented as the other rows' linear combination."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The number of rows is greater than the rank, so these vectors are not independent. Let's demonstrate that one vector can be defined as a linear combination of the other two vectors. Mathematically we represent this as:\n",
"\n",
"$x_1 \\mathit{v_1} + x_2 \\mathit{v_2} = v_3$\n",
"\n",
"or\n",
"\n",
"$[x_1 x_2][v_1; v_2] = v_3$\n",
"\n",
"This is not the usual linear algebra form of Ax = b. To get there, we transpose each side of the equation to get:\n",
"\n",
"$[v_1^T v_2^T][x_1; x_2] = v_3^T$\n",
"\n",
"which is the form Ax = b. We solve it in a least-squares sense."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[2. 1.]\n"
]
}
],
"source": [
"A = np.column_stack([v1, v2])\n",
"x = np.linalg.lstsq(A, v3, rcond=1)\n",
"print(x[0])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This shows that $v_3=2v_1+v_2$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We say that 2 vectors are orthogonal if they are perpendicular\n",
"to each other. i.e. the dot product of the two vectors is zero\n",
"\n",
"$(2,4,1).(3,-1,-3)=6-4-3=-1$\n",
"\n",
"Therefore, the two vectors are not orthogonal to each other. Now finding the project of $v_1$ on $v_2$.\n",
"\n",
"$Proj_{v_2}(v_1)=\\frac{v_1.u_1}{|v_2|^2}v_2=\\frac{-1}{\\sqrt{19}}(3,-1,-3)$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 3"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Matrix is Singular\n"
]
}
],
"source": [
"A = [[1,3],[2,6]]\n",
"if np.linalg.cond(A) < 1/sys.float_info.epsilon:\n",
" B = np.linalg.inv(A)\n",
"else:\n",
" print('Matrix is Singular')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYoAAAEGCAYAAAB7DNKzAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAf3klEQVR4nO3df3RU9Z3/8ec7IcBCEDVsx2oQ6ALboAGtkdpu228iWNCvSrHaYge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P7XNA1pYuZFZrZn8zsl0HXkiwKigxjZiOBi4DkfY9hZvsNcLa7TwReAv4j4HqSzswKge8DFwMTgKvNbEKwVaXcEeDf3b0MuAD4bB7MudPngOagi0gmBUXm+Q7wRSAvzjJw91+7+5Ho02eA0iDrSZHJwGZ33+Luh4F6YEbANaWUu7/i7n+MPt5Pxx/OM4KtKvXMrBT4v8A9QdeSTAqKDGJmlwM73H1D0LUEZD7w/4MuIgXOALZ3ed5CHvzR7GRmo4FzgTXBVpIW36XjH3qRoAtJJn3DXZqZWQNwWoxNNcCXgY+mt6LUizdnd38sOqaGjsMVdemsLU0sxmt50TGaWTHwM2CRu+8Lup5UMrNLgVfdfZ2ZVQZdTzIpKNLM3afGet3MyoExwAYzg45DMH80s8nuviuNJSZdd3PuZGZzgUuBKZ6bF/a0ACO7PC8FdgZUS9qYWREdIVHn7j8Pup40+BfgcjO7BBgMnGRmD7r77IDr6jddcJehzOxloMLds+0OlAkxs+nAt4H/4+6vBV1PKpjZADoW6qcAO4C1wKfcfVOghaWQdfxrZzmwx90XBV1PukU7isXufmnQtSSD1igkaHcBw4DfmNl6M7s76IKSLbpYfz3wJB2Luj/N5ZCI+hfgGuDC6O91ffRf2pKF1FGIiEhc6ihERCQuBYWIiMSloBARkbgUFCIiEpeCQkRE4lJQiIhIXAoKERGJS7fwEEmxkWUV5wM/ouMusoXAs8Antzc3PR9oYSK9pAvuRNJgZFnFN+i4/88/AC3bm5u+GXBJIr2mjkIkPb5Gxz2eDgL/FnAtIgnRGoVIepwKFNNxX6vBAdcikhAFhUh61AI30fF9G98KuBaRhCgoRFJsZFnFHODI9uamh4BbgfNHllVcGHBZIr2mxWwREYlLHYWIiMSloBARkbgUFCIiEpeCQkRE4lJQiIhIXAoKERGJS0EhIiJx/S996cjho5ssKgAAAABJRU5ErkJggg==\n",
"text/plain": [
"
"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"x = np.linspace(-5,5,100)\n",
"y = -1/3*x\n",
"plt.plot(x, y, '-r', label='x+3y=0')\n",
"plt.plot(x, y, 'og', label='2x+6y=0')\n",
"plt.xlabel('x', color='#1C2833')\n",
"plt.ylabel('y', color='#1C2833')\n",
"plt.legend(loc='upper left')\n",
"plt.grid()\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There are infinte many solutions, since we know that Matrix is Singular. The coefficients (a, b), which satisfies this equation with 1st row ($v_1$) and 2nd row ($v_2$) of the matrix: $av_1 + bv_2 = 0$ are (2, -1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 4"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Matrix is Singular\n"
]
}
],
"source": [
"A=[[1,4,-1],[3,2,7],[2,5,1]]\n",
"if np.linalg.cond(A) < 1/sys.float_info.epsilon:\n",
" B = np.linalg.inv(A)\n",
" print(B)\n",
"else:\n",
" print('Matrix is Singular')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Practice"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 1"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"x = np.sort(np.random.uniform(0,1,1000))\n",
"e = np.random.normal(0,1,1000)\n",
"y = 2+3*x+e"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"x0 = np.array([0.0, 0.0])\n",
"def opt(x, a, b):\n",
" return a + b*x\n",
"\n",
"sol = optimization.curve_fit(opt, x, y, x0, [1.0]*1000)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"y2 = sol[0][0] + sol[0][1]*x"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"image/png":...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here