Skip to content

Commit

Permalink
added HW-03
Browse files Browse the repository at this point in the history
  • Loading branch information
rcc02007 committed Oct 10, 2017
1 parent 4f66d7d commit d3f7b31
Show file tree
Hide file tree
Showing 5 changed files with 286 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -89,7 +89,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 25,
"metadata": {
"collapsed": false,
"slideshow": {
Expand Down Expand Up @@ -271,7 +271,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 26,
"metadata": {
"collapsed": false,
"slideshow": {
Expand Down Expand Up @@ -330,7 +330,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 28,
"metadata": {
"collapsed": false,
"slideshow": {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
"![Springs-masses](../09_Linear-Algebra/mass_springs.png)\n",
"\n",
Expand All @@ -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",
Expand All @@ -914,7 +898,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {
"collapsed": false,
"slideshow": {
Expand Down Expand Up @@ -956,7 +940,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 5,
"metadata": {
"collapsed": false,
"slideshow": {
Expand Down Expand Up @@ -985,7 +969,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 6,
"metadata": {
"collapsed": false,
"slideshow": {
Expand Down Expand Up @@ -1014,7 +998,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 7,
"metadata": {
"collapsed": false,
"slideshow": {
Expand Down Expand Up @@ -1042,7 +1026,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 9,
"metadata": {
"collapsed": false,
"slideshow": {
Expand Down Expand Up @@ -1071,7 +1055,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 10,
"metadata": {
"collapsed": false,
"slideshow": {
Expand Down Expand Up @@ -1114,7 +1098,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 14,
"metadata": {
"collapsed": false,
"slideshow": {
Expand All @@ -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)"
]
},
{
Expand Down Expand Up @@ -1194,7 +1172,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 32,
"metadata": {
"collapsed": false,
"slideshow": {
Expand All @@ -1206,33 +1184,35 @@
"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"
]
}
],
"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"
}
Expand All @@ -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",
Expand All @@ -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": {
Expand All @@ -1278,7 +1252,7 @@
"text": [
"ans =\n",
"\n",
" 0.325665420556713\n",
" 0.333333333333333\n",
" 0.666666666666667\n",
"\n",
"ans =\n",
Expand All @@ -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,
Expand Down
Loading

0 comments on commit d3f7b31

Please sign in to comment.