diff --git a/10_Gauss_elimination/.ipynb_checkpoints/10_Gauss_elimination-checkpoint.ipynb b/10_Gauss_elimination/.ipynb_checkpoints/10_Gauss_elimination-checkpoint.ipynb
index 1f6b0bb..e84e6dd 100644
--- a/10_Gauss_elimination/.ipynb_checkpoints/10_Gauss_elimination-checkpoint.ipynb
+++ b/10_Gauss_elimination/.ipynb_checkpoints/10_Gauss_elimination-checkpoint.ipynb
@@ -48,7 +48,7 @@
}
},
"source": [
- "Dimensions of a matrix = degrees of freedom of the system \n",
+ "Dimensions of unknown vector = degrees of freedom of the system \n",
"\n",
"- Given set of known outputs, $y_{1},~y_{2},~...y_{N}$ \n",
"- set of equations \n",
@@ -89,7 +89,7 @@
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": 25,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -271,7 +271,7 @@
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": 26,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -330,7 +330,7 @@
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": 28,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -748,22 +748,6 @@
}
],
"source": [
- "N=25;\n",
- "x11=linspace(-2,2,N);\n",
- "x12=linspace(-2,2,N);\n",
- "[X11,X12]=meshgrid(x11,x12);\n",
- "X13=1-10*X11-2*X12;\n",
- "\n",
- "x21=linspace(-2,2,N);\n",
- "x22=linspace(-2,2,N);\n",
- "[X21,X22]=meshgrid(x21,x22);\n",
- "X23=1-2*X11-X22;\n",
- "\n",
- "x31=linspace(-2,2,N);\n",
- "x32=linspace(-2,2,N);\n",
- "[X31,X32]=meshgrid(x31,x32);\n",
- "X33=1/10*(1-X31-2*X32);\n",
- "\n",
"mesh(X11,X12,X13);\n",
"hold on;\n",
"mesh(X21,X22,X23)\n",
@@ -879,7 +863,7 @@
"source": [
"## Mass-spring example\n",
"\n",
- "4 masses are connected in series to 4 springs with K=10 N/m. What are the final positions of the masses? \n",
+ "4 masses are connected in series to 4 springs with K=100N/m. What are the final positions of the masses? \n",
"\n",
"\n",
"\n",
@@ -893,7 +877,7 @@
"\n",
"$m_{4}g-k(x_{4}-x_{3})=0$\n",
"\n",
- "in matrix form:\n",
+ "in matrix form K=100 N/m:\n",
"\n",
"$\\left[ \\begin{array}{cccc}\n",
"2k & -k & 0 & 0 \\\\\n",
@@ -914,7 +898,7 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 4,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -956,7 +940,7 @@
},
{
"cell_type": "code",
- "execution_count": 12,
+ "execution_count": 5,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -985,7 +969,7 @@
},
{
"cell_type": "code",
- "execution_count": 14,
+ "execution_count": 6,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -1014,7 +998,7 @@
},
{
"cell_type": "code",
- "execution_count": 15,
+ "execution_count": 7,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -1042,7 +1026,7 @@
},
{
"cell_type": "code",
- "execution_count": 20,
+ "execution_count": 9,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -1071,7 +1055,7 @@
},
{
"cell_type": "code",
- "execution_count": 21,
+ "execution_count": 10,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -1114,7 +1098,7 @@
},
{
"cell_type": "code",
- "execution_count": 22,
+ "execution_count": 14,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -1126,18 +1110,12 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "x =\n",
- "\n",
- " 0.98100\n",
- " 1.86390\n",
- " 2.55060\n",
- " 2.94300\n",
- "\n"
+ "ans = Inf\r\n"
]
}
],
"source": [
- "x=GaussNaive(K,y)"
+ "%[x,Aug]=GaussNaive(K,y)"
]
},
{
@@ -1194,7 +1172,7 @@
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": 32,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -1206,17 +1184,17 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "ans =\n",
+ "x =\n",
"\n",
" NaN\n",
" NaN\n",
" NaN\n",
"\n",
- "ans =\n",
+ "Aug =\n",
"\n",
- " -5.423913\n",
- " 0.021739\n",
- " 2.652174\n",
+ " 0 2 3 8\n",
+ " NaN -Inf -Inf -Inf\n",
+ " NaN NaN NaN NaN\n",
"\n"
]
}
@@ -1224,15 +1202,17 @@
"source": [
"format short\n",
"Aa=[0,2,3;4,6,7;2,-3,6]; ya=[8;-3;5];\n",
- "GaussNaive(Aa,ya)\n",
- "Aa\\ya"
+ "%Aa([1,2],:)=Aa([2,1],:)\n",
+ "[x,Aug]=GaussNaive(Aa,ya)\n",
+ "%Aa\\ya"
]
},
{
"cell_type": "code",
- "execution_count": 7,
+ "execution_count": 29,
"metadata": {
"collapsed": false,
+ "scrolled": true,
"slideshow": {
"slide_type": "subslide"
}
@@ -1242,12 +1222,6 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "x =\n",
- "\n",
- " -5.423913\n",
- " 0.021739\n",
- " 2.652174\n",
- "\n",
"Aug =\n",
"\n",
" 4.00000 6.00000 7.00000 -3.00000\n",
@@ -1259,12 +1233,12 @@
}
],
"source": [
- "[x,Aug,npivots]=GaussPivot(Aa,ya)"
+ "[~,Aug,npivots]=GaussPivot(Aa,ya)"
]
},
{
"cell_type": "code",
- "execution_count": 33,
+ "execution_count": 24,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -1278,7 +1252,7 @@
"text": [
"ans =\n",
"\n",
- " 0.325665420556713\n",
+ " 0.333333333333333\n",
" 0.666666666666667\n",
"\n",
"ans =\n",
@@ -1291,11 +1265,30 @@
],
"source": [
"format long\n",
- "Ab=[0.3E-13,3.0000;1.0000,1.0000];yb=[2+0.1e-13;1.0000];\n",
- "GaussNaive(Ab,yb)\n",
+ "Ab=[0.3E-15,3.0000;1.0000,1.0000];yb=[2+0.1e-15;1.0000];\n",
+ "GaussPivot(Ab,yb)\n",
"Ab\\yb"
]
},
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "ans = 2.22044604925031e-16\r\n"
+ ]
+ }
+ ],
+ "source": [
+ "eps"
+ ]
+ },
{
"cell_type": "code",
"execution_count": 34,
diff --git a/10_Gauss_elimination/10_Gauss_elimination.ipynb b/10_Gauss_elimination/10_Gauss_elimination.ipynb
index 780de50..e423606 100644
--- a/10_Gauss_elimination/10_Gauss_elimination.ipynb
+++ b/10_Gauss_elimination/10_Gauss_elimination.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": 23,
+ "execution_count": 1,
"metadata": {
"collapsed": true,
"slideshow": {
@@ -16,7 +16,7 @@
},
{
"cell_type": "code",
- "execution_count": 24,
+ "execution_count": 2,
"metadata": {
"collapsed": true,
"slideshow": {
@@ -863,7 +863,7 @@
"source": [
"## Mass-spring example\n",
"\n",
- "4 masses are connected in series to 4 springs with K=10 N/m. What are the final positions of the masses? \n",
+ "4 masses are connected in series to 4 springs with K=100N/m. What are the final positions of the masses? \n",
"\n",
"\n",
"\n",
@@ -877,7 +877,7 @@
"\n",
"$m_{4}g-k(x_{4}-x_{3})=0$\n",
"\n",
- "in matrix form:\n",
+ "in matrix form K=100 N/m:\n",
"\n",
"$\\left[ \\begin{array}{cccc}\n",
"2k & -k & 0 & 0 \\\\\n",
@@ -940,7 +940,7 @@
},
{
"cell_type": "code",
- "execution_count": 12,
+ "execution_count": 5,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -969,7 +969,7 @@
},
{
"cell_type": "code",
- "execution_count": 14,
+ "execution_count": 6,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -998,7 +998,7 @@
},
{
"cell_type": "code",
- "execution_count": 15,
+ "execution_count": 7,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -1026,7 +1026,7 @@
},
{
"cell_type": "code",
- "execution_count": 20,
+ "execution_count": 9,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -1055,7 +1055,7 @@
},
{
"cell_type": "code",
- "execution_count": 21,
+ "execution_count": 4,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -1098,7 +1098,7 @@
},
{
"cell_type": "code",
- "execution_count": 22,
+ "execution_count": 5,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -1116,12 +1116,19 @@
" 1.86390\n",
" 2.55060\n",
" 2.94300\n",
+ "\n",
+ "Aug =\n",
+ "\n",
+ " 200.00000 -100.00000 0.00000 0.00000 9.81000\n",
+ " 0.00000 150.00000 -100.00000 0.00000 24.52500\n",
+ " 0.00000 0.00000 133.33333 -100.00000 45.78000\n",
+ " 0.00000 0.00000 0.00000 25.00000 73.57500\n",
"\n"
]
}
],
"source": [
- "x=GaussNaive(K,y)"
+ "[x,Aug]=GaussNaive(K,y)"
]
},
{
@@ -1178,7 +1185,7 @@
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": 8,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -1190,17 +1197,17 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "ans =\n",
+ "x =\n",
"\n",
" NaN\n",
" NaN\n",
" NaN\n",
"\n",
- "ans =\n",
+ "Aug =\n",
"\n",
- " -5.423913\n",
- " 0.021739\n",
- " 2.652174\n",
+ " 0 2 3 8\n",
+ " NaN -Inf -Inf -Inf\n",
+ " NaN NaN NaN NaN\n",
"\n"
]
}
@@ -1208,15 +1215,18 @@
"source": [
"format short\n",
"Aa=[0,2,3;4,6,7;2,-3,6]; ya=[8;-3;5];\n",
- "GaussNaive(Aa,ya)\n",
- "Aa\\ya"
+ "%Aa([1,3],:)=Aa([3,1],:)\n",
+ "%ya([1,3])=ya([3,1])\n",
+ "[x,Aug]=GaussNaive(Aa,ya)\n",
+ "%Aa\\ya"
]
},
{
"cell_type": "code",
- "execution_count": 7,
+ "execution_count": 12,
"metadata": {
"collapsed": false,
+ "scrolled": true,
"slideshow": {
"slide_type": "subslide"
}
@@ -1226,12 +1236,6 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "x =\n",
- "\n",
- " -5.423913\n",
- " 0.021739\n",
- " 2.652174\n",
- "\n",
"Aug =\n",
"\n",
" 4.00000 6.00000 7.00000 -3.00000\n",
@@ -1243,12 +1247,12 @@
}
],
"source": [
- "[x,Aug,npivots]=GaussPivot(Aa,ya)"
+ "[~,Aug,npivots]=GaussPivot(Aa,ya)"
]
},
{
"cell_type": "code",
- "execution_count": 33,
+ "execution_count": 21,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -1260,11 +1264,12 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "ans =\n",
+ "x =\n",
"\n",
- " 0.325665420556713\n",
+ " 0.333333333333333\n",
" 0.666666666666667\n",
"\n",
+ "0.33333333333333337034 0.66666666666666662966 \n",
"ans =\n",
"\n",
" 0.333333333333333\n",
@@ -1274,15 +1279,35 @@
}
],
"source": [
- "format long\n",
- "Ab=[0.3E-13,3.0000;1.0000,1.0000];yb=[2+0.1e-13;1.0000];\n",
- "GaussNaive(Ab,yb)\n",
+ "%format long\n",
+ "Ab=[0.3E-16,3.0000;1.0000,1.0000];yb=[2+1e-16;1.0000];\n",
+ "x=GaussPivot(Ab,yb)\n",
+ "fprintf('%1.20f ',x)\n",
"Ab\\yb"
]
},
{
"cell_type": "code",
- "execution_count": 34,
+ "execution_count": 20,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "ans = 2.22044604925031e-16\r\n"
+ ]
+ }
+ ],
+ "source": [
+ "eps"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 22,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -1301,8 +1326,8 @@
"\n",
"Aug =\n",
"\n",
- " 1.000000000000000 1.000000000000000 1.000000000000000\n",
- " 0.000000000000000 2.999999999999970 1.999999999999980\n",
+ " 1 1 1\n",
+ " 0 3 2\n",
"\n",
"npivots = 1\n",
"ans =\n",
@@ -1476,7 +1501,7 @@
},
{
"cell_type": "code",
- "execution_count": 25,
+ "execution_count": 23,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -1494,10 +1519,10 @@
"\n",
"ans =\n",
"\n",
- " 9.8100\n",
- " 27.4680\n",
- " 61.8030\n",
- " 101.0430\n",
+ " 0.98100\n",
+ " 1.86390\n",
+ " 2.55060\n",
+ " 2.94300\n",
"\n"
]
}
@@ -1512,7 +1537,7 @@
},
{
"cell_type": "code",
- "execution_count": 26,
+ "execution_count": 24,
"metadata": {
"collapsed": true,
"slideshow": {
@@ -1548,7 +1573,7 @@
},
{
"cell_type": "code",
- "execution_count": 28,
+ "execution_count": 25,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -1677,7 +1702,7 @@
"\t\n",
"\n",
"\n",
- "\t\n",
+ "\t\n",
"\t\n",
"\tMatlab \\\n",
"\n",
@@ -1686,7 +1711,7 @@
"\t\n",
"\n",
"\n",
- "\t\n",
+ "\t\n",
"\t\n",
"\tTriDiag\n",
"\n",
@@ -1695,7 +1720,7 @@
"\t\n",
"\n",
"\n",
- "\t\n",
+ "\t\n",
"\t\n",
"\n",
"\n",
diff --git a/10_Gauss_elimination/octave-workspace b/10_Gauss_elimination/octave-workspace
index 08dd0b6..2a6ff70 100644
Binary files a/10_Gauss_elimination/octave-workspace and b/10_Gauss_elimination/octave-workspace differ
diff --git a/HW3/README.md b/HW3/README.md
new file mode 100644
index 0000000..5e3329d
--- /dev/null
+++ b/HW3/README.md
@@ -0,0 +1,165 @@
+# Homework #3
+## Hand calculations
+
+The following problems should be worked out by hand. You can check your work with
+Matlab/Octave. Upload a pdf of the completed calculations into a github repository called
+'03_review_1-10'. Then, submit your repo link to
+(https://goo.gl/forms/xZ5AqRmSdugurwl33)[https://goo.gl/forms/xZ5AqRmSdugurwl33]
+
+1. Use the Newton-Raphson method to approximate when f(x)=0. Start with an initial guess
+of $x_{0}=0$.
+
+ $f(x)=e^{-x}-x^{3}$
+
+ a. Compute the first 3 iterations and calculate the approximate error for each.
+
+ b. Compare the exact derivative to the derivative used in the modified secant for
+ $\delta x=0.1$ and $\delta x=0.001$ at $x_{0}$.
+
+
+2. A simple computer is being assembled with 5-bits of storage for each integer.
+
+ a. How many different integers can be stored with 5 bits?
+
+ b. If we want the maximum number of positive and negative integers, what is the
+ largest and smallest integer we can store with 5 bits?
+
+3. Convert the following binary numbers to base-10 in two ways, 1- the exact conversion, and
+2- the conversion if only 4 digits are saved after addition/subtraction
+
+ a. 1.001
+
+ b. 100.1
+
+ c. 1.001 + 100.1
+
+ d. 1000 - 0.0001
+
+4. In Problem 3c-d what kind of error is introduced by limiting the number of digits
+stored?
+
+5. Solve the following problems with matrix A:
+
+ $A=\left[ \begin{array}{ccc}
+ 4 & 6 & 2 \\
+ 0 & 2 & 6 \\
+ 1 & 2 & 1\end{array} \right]$
+
+ a. Compute the LU-decomposition
+
+ b. Solve for x if $Ax=b$ and $b=\left[\begin{array}{c} 1\\2\\1\end{array}\right]$
+
+6. Solve the following problems with matrix A:
+
+ $A=\left[ \begin{array}{ccc}
+ 4 & -2 & 1\\
+ -2 & 4 & -2\\
+ 1 & -2 & 2\end{array} \right]$
+
+ a. Compute the Cholesky factorization of A
+
+ $C_{ii}=\sqrt{a_{ii}-\sum_{k=1}^{i-1}C_{ki}^{2}}$
+
+ $C_{ij}=\frac{a_{ij}-\sum_{k=1}^{i-1}C_{ki}C_{kj}}{C_{ii}}$.
+
+ b. Find the determinant of A, |A|.
+
+ c. Find the inverse of A, $A^{-1}$
+
+7.Determine the lower (L) and upper (U) triangular matrices with LU-decomposition for the
+following matrices, A. Then, solve for x when Ax=b:
+
+ a. $A=\left[ \begin{array}{cc}
+ 1 & 3 \\
+ 2 & 1 \end{array} \right]
+ b=
+ \left[\begin{array}{c}
+ 1 \\
+ 1\end{array}\right]$
+
+ a. $A=\left[ \begin{array}{cc}
+ 1 & 1 \\
+ 2 & 3 \end{array} \right]
+ b=
+ \left[\begin{array}{c}
+ 3 \\
+ 4\end{array}\right]$
+
+ a. $A=\left[ \begin{array}{cc}
+ 1 & 1 \\
+ 2 & -2 \end{array} \right]
+ b=
+ \left[\begin{array}{c}
+ 4 \\
+ 2\end{array}\right]$
+
+ b. $A=\left[ \begin{array}{ccc}
+ 1 & 3 & 1 \\
+ -4 & -9 & 2 \\
+ 0 & 3 & 5\end{array} \right]
+ b=
+ \left[\begin{array}{c}
+ 2 \\
+ 0 \\
+ 0\end{array}\right]$
+
+ c. $A=\left[ \begin{array}{ccc}
+ 1 & 2 & 3 \\
+ -4 & -3 & 2 \\
+ 0 & 3 & 5\end{array} \right]
+ b=
+ \left[\begin{array}{c}
+ 1 \\
+ -1 \\
+ -3\end{array}\right]$
+
+ d. $A=\left[ \begin{array}{ccc}
+ 1 & 3 & -5 \\
+ 1 & 4 & -8 \\
+ -3 & -7 & 9\end{array} \right]
+ b=
+ \left[\begin{array}{c}
+ 1 \\
+ -1 \\
+ -3\end{array}\right]$
+
+ d. $A=\left[ \begin{array}{ccc}
+ 0 & 2 & -1 \\
+ 2 & 5 & 2 \\
+ 1 & -1 & 2\end{array} \right]
+ b=
+ \left[\begin{array}{c}
+ 2 \\
+ 3 \\
+ 5\end{array}\right]$
+
+
+9. Calculate the determinant of A from 1a-g.
+
+10. Determine the Cholesky factorization, C, of the following matrices, where
+
+ $C_{ii}=\sqrt{a_{ii}-\sum_{k=1}^{i-1}C_{ki}^{2}}$
+
+ $C_{ij}=\frac{a_{ij}-\sum_{k=1}^{i-1}C_{ki}C_{kj}}{C_{ii}}$.
+
+ a. A=$\left[ \begin{array}{cc}
+ 3 & 2 \\
+ 2 & 1 \end{array} \right]$
+
+ a. A=$\left[ \begin{array}{cc}
+ 10 & 5 \\
+ 5 & 20 \end{array} \right]$
+
+ a. A=$\left[ \begin{array}{ccc}
+ 10 & -10 & 20 \\
+ -10 & 20 & 10 \\
+ 20 & 10 & 30 \end{array} \right]$
+
+ a. A=$\left[ \begin{array}{cccc}
+ 21 & -1 & 0 & 0 \\
+ -1 & 21 & -1 & 0 \\
+ 0 & -1 & 21 & -1 \\
+ 0 & 0 & -1 & 1 \end{array} \right]$
+
+11. Verify that $C^{T}C=A$ for 3a-d
+
diff --git a/HW3/README.pdf b/HW3/README.pdf
new file mode 100644
index 0000000..2880ee5
Binary files /dev/null and b/HW3/README.pdf differ