diff --git a/lecture_10/lecture_10.aux b/lecture_10/lecture_10.aux index 14a6f0d..d8d4c62 100644 --- a/lecture_10/lecture_10.aux +++ b/lecture_10/lecture_10.aux @@ -28,13 +28,13 @@ \@writefile{lof}{\contentsline {figure}{\numberline {1}{\ignorespaces Springs-masses\relax }}{4}{figure.caption.1}} \@writefile{toc}{\contentsline {subsection}{\numberline {1.2}Automate Gauss Elimination}{6}{subsection.1.2}} \newlabel{automate-gauss-elimination}{{1.2}{6}{Automate Gauss Elimination}{subsection.1.2}{}} -\@writefile{toc}{\contentsline {subsection}{\numberline {1.3}Problem (Diagonal element is zero)}{6}{subsection.1.3}} -\newlabel{problem-diagonal-element-is-zero}{{1.3}{6}{Problem (Diagonal element is zero)}{subsection.1.3}{}} -\@writefile{toc}{\contentsline {subsubsection}{\numberline {1.3.1}Spring-Mass System again}{8}{subsubsection.1.3.1}} -\newlabel{spring-mass-system-again}{{1.3.1}{8}{Spring-Mass System again}{subsubsection.1.3.1}{}} +\@writefile{toc}{\contentsline {subsection}{\numberline {1.3}Problem (Diagonal element is zero)}{7}{subsection.1.3}} +\newlabel{problem-diagonal-element-is-zero}{{1.3}{7}{Problem (Diagonal element is zero)}{subsection.1.3}{}} +\@writefile{toc}{\contentsline {subsubsection}{\numberline {1.3.1}Spring-Mass System again}{9}{subsubsection.1.3.1}} +\newlabel{spring-mass-system-again}{{1.3.1}{9}{Spring-Mass System again}{subsubsection.1.3.1}{}} \@writefile{lof}{\contentsline {figure}{\numberline {2}{\ignorespaces Springs-masses\relax }}{9}{figure.caption.2}} -\@writefile{toc}{\contentsline {subsection}{\numberline {1.4}Tridiagonal matrix}{9}{subsection.1.4}} -\newlabel{tridiagonal-matrix}{{1.4}{9}{Tridiagonal matrix}{subsection.1.4}{}} \gdef \LT@i {\LT@entry - {2}{67.64778pt}\LT@entry + {2}{61.69104pt}\LT@entry {1}{261.39424pt}} +\@writefile{toc}{\contentsline {subsection}{\numberline {1.4}Tridiagonal matrix}{10}{subsection.1.4}} +\newlabel{tridiagonal-matrix}{{1.4}{10}{Tridiagonal matrix}{subsection.1.4}{}} diff --git a/lecture_10/lecture_10.ipynb b/lecture_10/lecture_10.ipynb index 78e529d..46d4f00 100644 --- a/lecture_10/lecture_10.ipynb +++ b/lecture_10/lecture_10.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 14, + "execution_count": 1, "metadata": { "collapsed": true }, @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 2, "metadata": { "collapsed": true }, @@ -58,7 +58,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 3, "metadata": { "collapsed": false }, @@ -223,6 +223,30 @@ "plot(x11,x21,x21,x22)" ] }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ans =\n", + "\n", + " 0.40000\n", + " 0.20000\n", + "\n" + ] + } + ], + "source": [ + "A=[1,3;2,1]; y=[1;1];\n", + "A\\y % matlab's Ax=y solution for x" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -251,20 +275,11 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "error: 'X22' undefined near line 1 column 16\n", - "error: 'X13' undefined near line 1 column 14\n", - "error: evaluating argument list element number 3\n" - ] - }, { "data": { "image/svg+xml": [ @@ -312,282 +327,357 @@ "\n", "\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\n", + "\t\n", + "\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t-2\n", "\t\n", "\n", "\n", "\n", + "\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t-1.5\n", "\t\n", "\n", "\n", "\n", + "\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t-1\n", "\t\n", "\n", "\n", "\n", + "\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t-0.5\n", "\t\n", "\n", "\n", "\n", + "\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t0\n", "\t\n", "\n", "\n", "\n", + "\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t0.5\n", "\t\n", "\n", "\n", "\n", + "\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t1\n", "\t\n", "\n", "\n", "\n", + "\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t1.5\n", "\t\n", "\n", "\n", "\n", + "\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t2\n", "\t\n", "\n", "\n", "\n", + "\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t-2\n", "\t\n", "\n", "\n", "\n", + "\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t-1.5\n", "\t\n", "\n", "\n", "\n", + "\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t-1\n", "\t\n", "\n", "\n", "\n", + "\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t-0.5\n", "\t\n", "\n", "\n", "\n", + "\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t0\n", "\t\n", "\n", "\n", "\n", + "\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t0.5\n", "\t\n", "\n", "\n", "\n", + "\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t1\n", "\t\n", "\n", "\n", "\n", + "\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t1.5\n", "\t\n", "\n", "\n", "\n", + "\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t2\n", "\t\n", "\n", "\n", "\n", + "\n", + "\t\n", + "\n", + "\t\n", "\n", - "\t\t\n", - "\t\t-6\n", + "\t\t\n", + "\t\t-30\n", "\t\n", "\n", "\n", "\n", "\n", - "\t\n", + "\t\n", + "\n", + "\t\n", + "\n", + "\t\n", "\n", - "\t\t\n", - "\t\t-4\n", + "\t\t\n", + "\t\t-20\n", "\t\n", "\n", "\n", "\n", "\n", - "\t\n", + "\t\n", + "\n", + "\t\n", + "\n", + "\t\n", "\n", - "\t\t\n", - "\t\t-2\n", + "\t\t\n", + "\t\t-10\n", "\t\n", "\n", "\n", "\n", "\n", - "\t\n", + "\t\n", + "\n", + "\t\n", + "\n", + "\t\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t0\n", "\t\n", "\n", "\n", "\n", "\n", - "\t\n", + "\t\n", + "\n", + "\t\n", + "\n", + "\t\n", "\n", - "\t\t\n", - "\t\t2\n", + "\t\t\n", + "\t\t10\n", "\t\n", "\n", "\n", "\n", "\n", - "\t\n", + "\t\n", + "\n", + "\t\n", + "\n", + "\t\n", "\n", - "\t\t\n", - "\t\t4\n", + "\t\t\n", + "\t\t20\n", "\t\n", "\n", "\n", "\n", "\n", - "\t\n", + "\t\n", + "\n", + "\t\n", + "\n", + "\t\n", "\n", - "\t\t\n", - "\t\t6\n", + "\t\t\n", + "\t\t30\n", "\t\n", "\n", "\n", "\n", "\n", - "\t\n", - "\n", - "\t\t\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t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n", + "\t\n", + "\tgnuplot_plot_4a\n", + "\n", "\n", "\n", - "\t\n", + "\t\n", "\n", "\t\n", "\n", "\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\n", + "\t\n", "\n", - "\t\n", + "\t\t\n", + "\t\tx1\n", + "\t\n", + "\n", "\n", - "\t\n", + "\t\n", + "\t\tx2\n", + "\t\n", + "\n", + "\n", + "\t\n", + "\t\tx3\n", + "\t\n", + "\n", "\n", - "\t\n", + "\n", "\n", "" ], @@ -600,18 +690,19 @@ } ], "source": [ - "x11=linspace(-2,2,5);\n", - "x12=linspace(-2,2,5);\n", + "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*X22;\n", + "X13=1-10*X11-2*X12;\n", "\n", - "x21=linspace(-2,2,5);\n", - "x22=linspace(-2,2,5);\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,5);\n", - "x32=linspace(-2,2,5);\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", @@ -621,7 +712,10 @@ "mesh(X31,X32,X33)\n", "x=[10,2, 1;2,1, 1; 1, 2, 10]\\[1;1;1];\n", "plot3(x(1),x(2),x(3),'o')\n", - "view(45,45)" + "xlabel('x1')\n", + "ylabel('x2')\n", + "zlabel('x3')\n", + "view(10,45)" ] }, { @@ -676,7 +770,7 @@ "\n", "then, $3/5x_{2}+4/5(-1/5)=1$ so $x_{2}=\\frac{8}{5}$\n", "\n", - "finally, $10x_{1}+2(8/5)" + "finally, $10x_{1}+2(8/5)+1(-\\frac{1}{5})=1$" ] }, { @@ -720,7 +814,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 10, "metadata": { "collapsed": false }, @@ -759,7 +853,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 11, "metadata": { "collapsed": false }, @@ -785,7 +879,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 12, "metadata": { "collapsed": false }, @@ -811,7 +905,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 13, "metadata": { "collapsed": false }, @@ -836,7 +930,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 14, "metadata": { "collapsed": false }, @@ -862,7 +956,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 15, "metadata": { "collapsed": false }, @@ -898,7 +992,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 16, "metadata": { "collapsed": false }, @@ -962,7 +1056,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 17, "metadata": { "collapsed": false }, @@ -1000,7 +1094,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 32, "metadata": { "collapsed": false }, @@ -1031,7 +1125,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 33, "metadata": { "collapsed": false }, @@ -1062,7 +1156,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 34, "metadata": { "collapsed": false }, @@ -1096,6 +1190,28 @@ "format short" ] }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ans = -3.0000\n", + "ans = 3.0000\n" + ] + } + ], + "source": [ + "% determinant is (-1)^(number_of_pivots)*diagonal_elements\n", + "det(Ab)\n", + "Aug(1,1)*Aug(2,2)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -1138,7 +1254,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 24, "metadata": { "collapsed": false }, @@ -1211,13 +1327,13 @@ "\n", "|method |Number of Floating point operations for n$\\times$n-matrix|\n", "|----------------|---------|\n", - "| Naive Gauss | n-cubed |\n", + "| Gauss | n-cubed |\n", "| Tridiagonal | n |" ] }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 25, "metadata": { "collapsed": false }, @@ -1229,6 +1345,13 @@ "ans =\n", "\n", " 9.8100 27.4680 61.8030 101.0430\n", + "\n", + "ans =\n", + "\n", + " 9.8100\n", + " 27.4680\n", + " 61.8030\n", + " 101.0430\n", "\n" ] } @@ -1237,12 +1360,13 @@ "e=[0;-5;-2;-1];\n", "g=[-5;-2;-1;0];\n", "f=[15;7;3;1];\n", - "Tridiag(e,f,g,y)\n" + "Tridiag(e,f,g,y)\n", + "K\\y\n" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 26, "metadata": { "collapsed": true }, @@ -1265,7 +1389,7 @@ " x = GaussPivot(A,b);\n", " t_GE(n) = toc;\n", " tic;\n", - " x = GaussPivot(Atd,b);\n", + " x = A\\b;\n", " t_GE_tridiag(n) = toc;\n", " tic;\n", " x = Tridiag(e,f,g,b);\n", @@ -1275,7 +1399,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 28, "metadata": { "collapsed": false }, @@ -1329,26 +1453,31 @@ "\n", "\n", "\t\t\n", + "\t\t10-5\n", + "\t\n", + "\n", + "\n", + "\t\t\n", "\t\t10-4\n", "\t\n", "\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t10-3\n", "\t\n", "\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t10-2\n", "\t\n", "\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t10-1\n", "\t\n", "\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t100\n", "\t\n", "\n", @@ -1358,21 +1487,16 @@ "\t\n", "\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t101\n", "\t\n", "\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t102\n", "\t\n", "\n", "\n", - "\t\t\n", - "\t\t103\n", - "\t\n", - "\n", - "\n", "\n", "\n", "\t\n", @@ -1388,19 +1512,38 @@ "\n", "\n", "\n", - "\tgnuplot_plot_1a\n", - "\n", + "\n", + "\n", + "\n", + "\t\n", + "\tGauss elim\n", + "\n", "\n", "\n", - "\t\n", + "\t\n", + "\t\tGauss elim\n", "\t\n", - "\tgnuplot_plot_2a\n", + "\n", "\n", - "\t\n", + "\t\n", "\t\n", - "\tgnuplot_plot_3a\n", + "\tMatlab \\\n", + "\n", + "\t\n", + "\t\tMatlab \n", + "\t\n", + "\n", + "\n", + "\t\n", + "\t\n", + "\tTriDiag\n", "\n", - "\t\n", + "\t\n", + "\t\tTriDiag\n", + "\t\n", + "\n", + "\n", + "\t\n", "\t\n", "\n", "\n", @@ -1422,12 +1565,92 @@ } ], "source": [ - "n=1:200;\n", + "n=1:100;\n", "loglog(n,t_GE,n,t_TD,n,t_GE_tridiag)\n", + "legend('Gauss elim','Matlab \\','TriDiag')\n", "xlabel('number of elements')\n", "ylabel('time (s)')" ] }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "x =\n", + "\n", + " 9.8100\n", + " 27.4680\n", + " 61.8030\n", + " 101.0430\n", + "\n", + "Aug =\n", + "\n", + " 15.00000 -5.00000 0.00000 0.00000 9.81000\n", + " 0.00000 5.33333 -2.00000 0.00000 22.89000\n", + " 0.00000 0.00000 2.25000 -1.00000 38.01375\n", + " 0.00000 0.00000 0.00000 0.55556 56.13500\n", + "\n", + "npivots = 0\n" + ] + } + ], + "source": [ + "[x,Aug,npivots]=GaussPivot(K,y)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "A =\n", + "\n", + " 15.00000 -5.00000 0.00000 0.00000\n", + " 0.00000 5.33333 -2.00000 0.00000\n", + " 0.00000 0.00000 2.25000 -1.00000\n", + " 0.00000 0.00000 0.00000 0.55556\n", + "\n" + ] + } + ], + "source": [ + "A=Aug(1:4,1:4)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ans = 100.00\n", + "detA = 100.00\n" + ] + } + ], + "source": [ + "det(A)\n", + "detA=A(1,1)*A(2,2)*A(3,3)*A(4,4)" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/lecture_10/lecture_10.log b/lecture_10/lecture_10.log index 088d911..9e3113d 100644 --- a/lecture_10/lecture_10.log +++ b/lecture_10/lecture_10.log @@ -1,4 +1,4 @@ -This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015/Debian) (preloaded format=pdflatex 2017.1.11) 20 FEB 2017 17:21 +This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015/Debian) (preloaded format=pdflatex 2017.1.11) 21 FEB 2017 11:46 entering extended mode restricted \write18 enabled. %&-line parsing enabled. @@ -772,28 +772,27 @@ Underfull \hbox (badness 10000) in paragraph at lines 323--324 [] -[2 <./lecture_10_files/lecture_10_3_0.pdf>] -LaTeX Font Info: Try loading font information for TS1+cmtt on input line 359 +LaTeX Font Info: Try loading font information for TS1+cmtt on input line 327 . - (/usr/share/texlive/texmf-dist/tex/latex/base/ts1cmtt.fd File: ts1cmtt.fd 2014/09/29 v2.5h Standard LaTeX font definitions -) - -File: lecture_10_files/lecture_10_5_1.pdf Graphic file (type pdf) +) [2 <./lecture_10_files/lecture_10_3_0.pdf>] + +File: lecture_10_files/lecture_10_6_0.pdf Graphic file (type pdf) - -Package pdftex.def Info: lecture_10_files/lecture_10_5_1.pdf used on input line - 371. + +Package pdftex.def Info: lecture_10_files/lecture_10_6_0.pdf used on input line + 382. (pdftex.def) Requested size: 449.6789pt x 337.25917pt. -Underfull \hbox (badness 10000) in paragraph at lines 373--374 +Underfull \hbox (badness 10000) in paragraph at lines 384--385 [] +[3 <./lecture_10_files/lecture_10_6_0.pdf>] LaTeX Font Info: Font shape `T1/ppl/bx/n' in size <12> not available -(Font) Font shape `T1/ppl/b/n' tried instead on input line 378. -[3 <./lecture_10_files/lecture_10_5_1.pdf>] +(Font) Font shape `T1/ppl/b/n' tried instead on input line 389. + ! LaTeX Error: Unknown graphics extension: .svg. @@ -801,10 +800,10 @@ See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help. ... -l.433 ...egraphics{../lecture_09/mass_springs.svg} +l.444 ...egraphics{../lecture_09/mass_springs.svg} ? -[4] [5] [6] [7] +[4] [5] [6] [7] [8] ! LaTeX Error: Unknown graphics extension: .svg. @@ -812,45 +811,45 @@ See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help. ... -l.712 ...egraphics{../lecture_09/mass_springs.svg} +l.735 ...egraphics{../lecture_09/mass_springs.svg} ? -[8] [9] +[9] [10] LaTeX Font Info: Font shape `T1/cmtt/bx/n' in size <10.95> not available -(Font) Font shape `T1/cmtt/m/n' tried instead on input line 812. - [10] - -File: lecture_10_files/lecture_10_27_0.pdf Graphic file (type pdf) - - -Package pdftex.def Info: lecture_10_files/lecture_10_27_0.pdf used on input lin -e 839. -(pdftex.def) Requested size: 449.6789pt x 337.25917pt. +(Font) Font shape `T1/cmtt/m/n' tried instead on input line 843. + +File: lecture_10_files/lecture_10_29_0.pdf Graphic file (type pdf) -Underfull \hbox (badness 10000) in paragraph at lines 841--842 + +Package pdftex.def Info: lecture_10_files/lecture_10_29_0.pdf used on input lin +e 871. +(pdftex.def) Requested size: 449.6789pt x 337.25917pt. + [11] +Underfull \hbox (badness 10000) in paragraph at lines 873--874 [] -Package atveryend Info: Empty hook `BeforeClearDocument' on input line 852. -[11 <./lecture_10_files/lecture_10_27_0.pdf>] -Package atveryend Info: Empty hook `AfterLastShipout' on input line 852. +[12 <./lecture_10_files/lecture_10_29_0.pdf>] +Package atveryend Info: Empty hook `BeforeClearDocument' on input line 933. + [13] +Package atveryend Info: Empty hook `AfterLastShipout' on input line 933. (./lecture_10.aux) -Package atveryend Info: Executing hook `AtVeryEndDocument' on input line 852. -Package atveryend Info: Executing hook `AtEndAfterFileList' on input line 852. +Package atveryend Info: Executing hook `AtVeryEndDocument' on input line 933. +Package atveryend Info: Executing hook `AtEndAfterFileList' on input line 933. Package rerunfilecheck Info: File `lecture_10.out' has not changed. (rerunfilecheck) Checksum: F41F49C8B1F4406369908EBDD24F2572;629. LaTeX Warning: There were multiply-defined labels. -Package atveryend Info: Empty hook `AtVeryVeryEnd' on input line 852. +Package atveryend Info: Empty hook `AtVeryVeryEnd' on input line 933. ) Here is how much of TeX's memory you used: - 10939 strings out of 493029 - 163764 string characters out of 6136234 - 273062 words of memory out of 5000000 - 14225 multiletter control sequences out of 15000+600000 - 35480 words of font info for 90 fonts, out of 8000000 for 9000 + 10943 strings out of 493029 + 163805 string characters out of 6136234 + 273063 words of memory out of 5000000 + 14226 multiletter control sequences out of 15000+600000 + 35779 words of font info for 91 fonts, out of 8000000 for 9000 1141 hyphenation exceptions out of 8191 36i,8n,77p,494b,465s stack positions out of 5000i,500n,10000p,200000b,80000s {/usr/share/texmf/fonts/enc/dvips/cm-super/cm-super-ts1.enc}{/usr/share/texli @@ -863,10 +862,10 @@ fb> -Output written on lecture_10.pdf (11 pages, 162693 bytes). +Output written on lecture_10.pdf (13 pages, 190161 bytes). PDF statistics: - 165 PDF objects out of 1000 (max. 8388607) - 133 compressed objects within 2 object streams - 27 named destinations out of 1000 (max. 500000) + 176 PDF objects out of 1000 (max. 8388607) + 142 compressed objects within 2 object streams + 29 named destinations out of 1000 (max. 500000) 80 words of extra memory for PDF output out of 10000 (max. 10000000) diff --git a/lecture_10/lecture_10.pdf b/lecture_10/lecture_10.pdf index 447bbe2..d75909f 100644 Binary files a/lecture_10/lecture_10.pdf and b/lecture_10/lecture_10.pdf differ diff --git a/lecture_10/lecture_10.tex b/lecture_10/lecture_10.tex index 1131881..633c945 100644 --- a/lecture_10/lecture_10.tex +++ b/lecture_10/lecture_10.tex @@ -277,11 +277,11 @@ \begin{Verbatim}[commandchars=\\\{\}] -{\color{incolor}In [{\color{incolor}14}]:} \PY{c}{\PYZpc{}plot \PYZhy{}\PYZhy{}format svg} +{\color{incolor}In [{\color{incolor}1}]:} \PY{c}{\PYZpc{}plot \PYZhy{}\PYZhy{}format svg} \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] -{\color{incolor}In [{\color{incolor}15}]:} \PY{n}{setdefaults} +{\color{incolor}In [{\color{incolor}2}]:} \PY{n}{setdefaults} \end{Verbatim} \section{Gauss Elimination}\label{gauss-elimination} @@ -310,11 +310,11 @@ The solution for \(x_{1}\) and \(x_{2}\) is the intersection of two lines: \begin{Verbatim}[commandchars=\\\{\}] -{\color{incolor}In [{\color{incolor}16}]:} \PY{n}{x21}\PY{p}{=}\PY{p}{[}\PY{o}{\PYZhy{}}\PY{l+m+mi}{2}\PY{p}{:}\PY{l+m+mi}{2}\PY{p}{]}\PY{p}{;} - \PY{n}{x11}\PY{p}{=}\PY{l+m+mi}{1}\PY{o}{\PYZhy{}}\PY{l+m+mi}{3}\PY{o}{*}\PY{n}{x21}\PY{p}{;} - \PY{n}{x21}\PY{p}{=}\PY{p}{[}\PY{o}{\PYZhy{}}\PY{l+m+mi}{2}\PY{p}{:}\PY{l+m+mi}{2}\PY{p}{]}\PY{p}{;} - \PY{n}{x22}\PY{p}{=}\PY{l+m+mi}{1}\PY{o}{\PYZhy{}}\PY{l+m+mi}{2}\PY{o}{*}\PY{n}{x21}\PY{p}{;} - \PY{n+nb}{plot}\PY{p}{(}\PY{n}{x11}\PY{p}{,}\PY{n}{x21}\PY{p}{,}\PY{n}{x21}\PY{p}{,}\PY{n}{x22}\PY{p}{)} +{\color{incolor}In [{\color{incolor}3}]:} \PY{n}{x21}\PY{p}{=}\PY{p}{[}\PY{o}{\PYZhy{}}\PY{l+m+mi}{2}\PY{p}{:}\PY{l+m+mi}{2}\PY{p}{]}\PY{p}{;} + \PY{n}{x11}\PY{p}{=}\PY{l+m+mi}{1}\PY{o}{\PYZhy{}}\PY{l+m+mi}{3}\PY{o}{*}\PY{n}{x21}\PY{p}{;} + \PY{n}{x21}\PY{p}{=}\PY{p}{[}\PY{o}{\PYZhy{}}\PY{l+m+mi}{2}\PY{p}{:}\PY{l+m+mi}{2}\PY{p}{]}\PY{p}{;} + \PY{n}{x22}\PY{p}{=}\PY{l+m+mi}{1}\PY{o}{\PYZhy{}}\PY{l+m+mi}{2}\PY{o}{*}\PY{n}{x21}\PY{p}{;} + \PY{n+nb}{plot}\PY{p}{(}\PY{n}{x11}\PY{p}{,}\PY{n}{x21}\PY{p}{,}\PY{n}{x21}\PY{p}{,}\PY{n}{x22}\PY{p}{)} \end{Verbatim} \begin{center} @@ -322,7 +322,21 @@ lines: \end{center} { \hspace*{\fill} \\} - For a $3\times3$ matrix, the solution is the intersection of the 3 + \begin{Verbatim}[commandchars=\\\{\}] +{\color{incolor}In [{\color{incolor}4}]:} \PY{n}{A}\PY{p}{=}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{,}\PY{l+m+mi}{3}\PY{p}{;}\PY{l+m+mi}{2}\PY{p}{,}\PY{l+m+mi}{1}\PY{p}{]}\PY{p}{;} \PY{n}{y}\PY{p}{=}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{;}\PY{l+m+mi}{1}\PY{p}{]}\PY{p}{;} + \PY{n}{A}\PY{o}{\PYZbs{}}\PY{n}{y} \PY{c}{\PYZpc{} matlab\PYZsq{}s Ax=y solution for x} +\end{Verbatim} + + \begin{Verbatim}[commandchars=\\\{\}] +ans = + + 0.40000 + 0.20000 + + + \end{Verbatim} + + For a \(3\times3\) matrix, the solution is the intersection of the 3 planes. \(10x_{1}+2x_{2}+x_{3}=1\) @@ -331,44 +345,41 @@ planes. \(x_{1}+2x_{2}+10x_{3}=1\) -$\left[ \begin{array}{ccc} 10 & 2 & 1 \\ 2 & 1 & 1 \\ 1 & 2 & 10\end{array} \right] +$\left[ \begin{array}{ccc} 10 & 2 & 1\\ 2 & 1 & 1 \\ 1 & 2 & 10\end{array} \right] \left[\begin{array}{c} x_{1} \\ x_{2} \\ x_{3} \end{array}\right]= \left[\begin{array}{c} 1 \\ 1 \\ 1\end{array}\right]$ \begin{Verbatim}[commandchars=\\\{\}] -{\color{incolor}In [{\color{incolor}17}]:} \PY{n}{x11}\PY{p}{=}\PY{n+nb}{linspace}\PY{p}{(}\PY{o}{\PYZhy{}}\PY{l+m+mi}{2}\PY{p}{,}\PY{l+m+mi}{2}\PY{p}{,}\PY{l+m+mi}{5}\PY{p}{)}\PY{p}{;} - \PY{n}{x12}\PY{p}{=}\PY{n+nb}{linspace}\PY{p}{(}\PY{o}{\PYZhy{}}\PY{l+m+mi}{2}\PY{p}{,}\PY{l+m+mi}{2}\PY{p}{,}\PY{l+m+mi}{5}\PY{p}{)}\PY{p}{;} - \PY{p}{[}\PY{n}{X11}\PY{p}{,}\PY{n}{X12}\PY{p}{]}\PY{p}{=}\PY{n+nb}{meshgrid}\PY{p}{(}\PY{n}{x11}\PY{p}{,}\PY{n}{x12}\PY{p}{)}\PY{p}{;} - \PY{n}{X13}\PY{p}{=}\PY{l+m+mi}{1}\PY{o}{\PYZhy{}}\PY{l+m+mi}{10}\PY{o}{*}\PY{n}{X11}\PY{o}{\PYZhy{}}\PY{l+m+mi}{2}\PY{o}{*}\PY{n}{X22}\PY{p}{;} - - \PY{n}{x21}\PY{p}{=}\PY{n+nb}{linspace}\PY{p}{(}\PY{o}{\PYZhy{}}\PY{l+m+mi}{2}\PY{p}{,}\PY{l+m+mi}{2}\PY{p}{,}\PY{l+m+mi}{5}\PY{p}{)}\PY{p}{;} - \PY{n}{x22}\PY{p}{=}\PY{n+nb}{linspace}\PY{p}{(}\PY{o}{\PYZhy{}}\PY{l+m+mi}{2}\PY{p}{,}\PY{l+m+mi}{2}\PY{p}{,}\PY{l+m+mi}{5}\PY{p}{)}\PY{p}{;} - \PY{p}{[}\PY{n}{X21}\PY{p}{,}\PY{n}{X22}\PY{p}{]}\PY{p}{=}\PY{n+nb}{meshgrid}\PY{p}{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n}{x}\PY{p}{(}\PY{l+m+mi}{3}\PY{p}{)}\PY{p}{,}\PY{l+s}{\PYZsq{}}\PY{l+s}{o\PYZsq{}}\PY{p}{)} + \PY{n+nb}{xlabel}\PY{p}{(}\PY{l+s}{\PYZsq{}}\PY{l+s}{x1\PYZsq{}}\PY{p}{)} + \PY{n+nb}{ylabel}\PY{p}{(}\PY{l+s}{\PYZsq{}}\PY{l+s}{x2\PYZsq{}}\PY{p}{)} + \PY{n+nb}{zlabel}\PY{p}{(}\PY{l+s}{\PYZsq{}}\PY{l+s}{x3\PYZsq{}}\PY{p}{)} + \PY{n+nb}{view}\PY{p}{(}\PY{l+m+mi}{10}\PY{p}{,}\PY{l+m+mi}{45}\PY{p}{)} \end{Verbatim} - \begin{Verbatim}[commandchars=\\\{\}] -error: 'X22' undefined near line 1 column 16 -error: 'X13' undefined near line 1 column 14 -error: evaluating argument list element number 3 - - \end{Verbatim} - \begin{center} - \adjustimage{max size={0.9\linewidth}{0.9\paperheight}}{lecture_10_files/lecture_10_5_1.pdf} + \adjustimage{max size={0.9\linewidth}{0.9\paperheight}}{lecture_10_files/lecture_10_6_0.pdf} \end{center} { \hspace*{\fill} \\} @@ -416,13 +427,13 @@ $\left[ 10 & 2 & 1 & 1\\ 0 & 3/5 & 4/5 & 4/5 \\ 0 & 0 & 7.5 & -1.5\end{array} -\right] $ +\right]$ now, \(7.5x_{3}=-1.5\) so \(x_{3}=-\frac{1}{5}\) then, \(3/5x_{2}+4/5(-1/5)=1\) so \(x_{2}=\frac{8}{5}\) -finally, \$10x\_\{1\}+2(8/5) +finally, \(10x_{1}+2(8/5)+1(-\frac{1}{5})=1\) Consider the problem again from the intro to Linear Algebra, 4 masses are connected in series to 4 springs with K=10 N/m. What are the final @@ -450,7 +461,7 @@ in matrix form: \(\left[ \begin{array}{cccc} 2k & -k & 0 & 0 \\ -k & 2k & -k & 0 \\ 0 & -k & 2k & -k \\ 0 & 0 & -k & k \end{array} \right] \left[ \begin{array}{c} x_{1} \\ x_{2} \\ x_{3} \\ x_{4} \end{array} \right]= \left[ \begin{array}{c} m_{1}g \\ m_{2}g \\ m_{3}g \\ m_{4}g \end{array} \right]\) \begin{Verbatim}[commandchars=\\\{\}] -{\color{incolor}In [{\color{incolor}18}]:} \PY{n}{k}\PY{p}{=}\PY{l+m+mi}{10}\PY{p}{;} \PY{c}{\PYZpc{} N/m} +{\color{incolor}In [{\color{incolor}10}]:} \PY{n}{k}\PY{p}{=}\PY{l+m+mi}{10}\PY{p}{;} \PY{c}{\PYZpc{} N/m} \PY{n}{m1}\PY{p}{=}\PY{l+m+mi}{1}\PY{p}{;} \PY{c}{\PYZpc{} kg} \PY{n}{m2}\PY{p}{=}\PY{l+m+mi}{2}\PY{p}{;} \PY{n}{m3}\PY{p}{=}\PY{l+m+mi}{3}\PY{p}{;} @@ -479,7 +490,7 @@ y = \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] -{\color{incolor}In [{\color{incolor}19}]:} \PY{n}{K1}\PY{p}{=}\PY{p}{[}\PY{n}{K} \PY{n}{y}\PY{p}{]}\PY{p}{;} +{\color{incolor}In [{\color{incolor}11}]:} \PY{n}{K1}\PY{p}{=}\PY{p}{[}\PY{n}{K} \PY{n}{y}\PY{p}{]}\PY{p}{;} \PY{n}{K1}\PY{p}{(}\PY{l+m+mi}{2}\PY{p}{,}\PY{p}{:}\PY{p}{)}\PY{p}{=}\PY{n}{K1}\PY{p}{(}\PY{l+m+mi}{1}\PY{p}{,}\PY{p}{:}\PY{p}{)}\PY{o}{/}\PY{l+m+mi}{2}\PY{o}{+}\PY{n}{K1}\PY{p}{(}\PY{l+m+mi}{2}\PY{p}{,}\PY{p}{:}\PY{p}{)} \end{Verbatim} @@ -495,7 +506,7 @@ K1 = \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] -{\color{incolor}In [{\color{incolor}20}]:} \PY{n}{K2}\PY{p}{=}\PY{n}{K1}\PY{p}{;} +{\color{incolor}In [{\color{incolor}12}]:} \PY{n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m+mi}{3}\PY{p}{)}\PY{o}{+}\PY{n}{K2}\PY{p}{(}\PY{l+m+mi}{4}\PY{p}{,}\PY{p}{:}\PY{p}{)} \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] @@ -526,7 +537,7 @@ K2 = \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] -{\color{incolor}In [{\color{incolor}22}]:} \PY{n}{yp}\PY{p}{=}\PY{n}{K2}\PY{p}{(}\PY{p}{:}\PY{p}{,}\PY{l+m+mi}{5}\PY{p}{)}\PY{p}{;} +{\color{incolor}In [{\color{incolor}14}]:} \PY{n}{yp}\PY{p}{=}\PY{n}{K2}\PY{p}{(}\PY{p}{:}\PY{p}{,}\PY{l+m+mi}{5}\PY{p}{)}\PY{p}{;} \PY{n}{x4}\PY{p}{=}\PY{n}{yp}\PY{p}{(}\PY{l+m+mi}{4}\PY{p}{)}\PY{o}{/}\PY{n}{K2}\PY{p}{(}\PY{l+m+mi}{4}\PY{p}{,}\PY{l+m+mi}{4}\PY{p}{)} \PY{n}{x3}\PY{p}{=}\PY{p}{(}\PY{n}{yp}\PY{p}{(}\PY{l+m+mi}{3}\PY{p}{)}\PY{o}{+}\PY{l+m+mi}{10}\PY{o}{*}\PY{n}{x4}\PY{p}{)}\PY{o}{/}\PY{n}{K2}\PY{p}{(}\PY{l+m+mi}{3}\PY{p}{,}\PY{l+m+mi}{3}\PY{p}{)} \PY{n}{x2}\PY{p}{=}\PY{p}{(}\PY{n}{yp}\PY{p}{(}\PY{l+m+mi}{2}\PY{p}{)}\PY{o}{+}\PY{l+m+mi}{10}\PY{o}{*}\PY{n}{x3}\PY{p}{)}\PY{o}{/}\PY{n}{K2}\PY{p}{(}\PY{l+m+mi}{2}\PY{p}{,}\PY{l+m+mi}{2}\PY{p}{)} @@ -542,7 +553,7 @@ x1 = 9.8100 \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] -{\color{incolor}In [{\color{incolor}23}]:} \PY{n}{K}\PY{o}{\PYZbs{}}\PY{n}{y} +{\color{incolor}In [{\color{incolor}15}]:} \PY{n}{K}\PY{o}{\PYZbs{}}\PY{n}{y} \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] @@ -565,7 +576,7 @@ y: \texttt{x=GaussNaive(A,y)} \begin{Verbatim}[commandchars=\\\{\}] -{\color{incolor}In [{\color{incolor}24}]:} \PY{n}{x}\PY{p}{=}\PY{n}{GaussNaive}\PY{p}{(}\PY{n}{K}\PY{p}{,}\PY{n}{y}\PY{p}{)} +{\color{incolor}In [{\color{incolor}16}]:} \PY{n}{x}\PY{p}{=}\PY{n}{GaussNaive}\PY{p}{(}\PY{n}{K}\PY{p}{,}\PY{n}{y}\PY{p}{)} \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] @@ -606,7 +617,7 @@ Consider: \end{enumerate} \begin{Verbatim}[commandchars=\\\{\}] -{\color{incolor}In [{\color{incolor}25}]:} \PY{n}{format} \PY{n}{short} +{\color{incolor}In [{\color{incolor}17}]:} \PY{n}{format} \PY{n}{short} \PY{n}{Aa}\PY{p}{=}\PY{p}{[}\PY{l+m+mi}{0}\PY{p}{,}\PY{l+m+mi}{2}\PY{p}{,}\PY{l+m+mi}{3}\PY{p}{;}\PY{l+m+mi}{4}\PY{p}{,}\PY{l+m+mi}{6}\PY{p}{,}\PY{l+m+mi}{7}\PY{p}{;}\PY{l+m+mi}{2}\PY{p}{,}\PY{o}{\PYZhy{}}\PY{l+m+mi}{3}\PY{p}{,}\PY{l+m+mi}{6}\PY{p}{]}\PY{p}{;} \PY{n}{ya}\PY{p}{=}\PY{p}{[}\PY{l+m+mi}{8}\PY{p}{;}\PY{o}{\PYZhy{}}\PY{l+m+mi}{3}\PY{p}{;}\PY{l+m+mi}{5}\PY{p}{]}\PY{p}{;} \PY{n}{GaussNaive}\PY{p}{(}\PY{n}{Aa}\PY{p}{,}\PY{n}{ya}\PY{p}{)} \PY{n}{Aa}\PY{o}{\PYZbs{}}\PY{n}{ya} @@ -634,7 +645,7 @@ ans = \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] -{\color{incolor}In [{\color{incolor}26}]:} \PY{p}{[}\PY{n}{x}\PY{p}{,}\PY{n}{Aug}\PY{p}{,}\PY{n}{npivots}\PY{p}{]}\PY{p}{=}\PY{n}{GaussPivot}\PY{p}{(}\PY{n}{Aa}\PY{p}{,}\PY{n}{ya}\PY{p}{)} +{\color{incolor}In [{\color{incolor}32}]:} \PY{p}{[}\PY{n}{x}\PY{p}{,}\PY{n}{Aug}\PY{p}{,}\PY{n}{npivots}\PY{p}{]}\PY{p}{=}\PY{n}{GaussPivot}\PY{p}{(}\PY{n}{Aa}\PY{p}{,}\PY{n}{ya}\PY{p}{)} \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] @@ -655,7 +666,7 @@ npivots = 2 \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] -{\color{incolor}In [{\color{incolor}27}]:} \PY{n}{format} \PY{n}{long} +{\color{incolor}In [{\color{incolor}33}]:} \PY{n}{format} \PY{n}{long} \PY{n}{Ab}\PY{p}{=}\PY{p}{[}\PY{l+m+mf}{0.3E\PYZhy{}13}\PY{p}{,}\PY{l+m+mf}{3.0000}\PY{p}{;}\PY{l+m+mf}{1.0000}\PY{p}{,}\PY{l+m+mf}{1.0000}\PY{p}{]}\PY{p}{;}\PY{n}{yb}\PY{p}{=}\PY{p}{[}\PY{l+m+mi}{2}\PY{o}{+}\PY{l+m+mf}{0.1e\PYZhy{}13}\PY{p}{;}\PY{l+m+mf}{1.0000}\PY{p}{]}\PY{p}{;} \PY{n}{GaussNaive}\PY{p}{(}\PY{n}{Ab}\PY{p}{,}\PY{n}{yb}\PY{p}{)} \PY{n}{Ab}\PY{o}{\PYZbs{}}\PY{n}{yb} @@ -676,7 +687,7 @@ ans = \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] -{\color{incolor}In [{\color{incolor}28}]:} \PY{p}{[}\PY{n}{x}\PY{p}{,}\PY{n}{Aug}\PY{p}{,}\PY{n}{npivots}\PY{p}{]}\PY{p}{=}\PY{n}{GaussPivot}\PY{p}{(}\PY{n}{Ab}\PY{p}{,}\PY{n}{yb}\PY{p}{)} +{\color{incolor}In [{\color{incolor}34}]:} \PY{p}{[}\PY{n}{x}\PY{p}{,}\PY{n}{Aug}\PY{p}{,}\PY{n}{npivots}\PY{p}{]}\PY{p}{=}\PY{n}{GaussPivot}\PY{p}{(}\PY{n}{Ab}\PY{p}{,}\PY{n}{yb}\PY{p}{)} \PY{n}{Ab}\PY{o}{\PYZbs{}}\PY{n}{yb} \PY{n}{format} \PY{n}{short} \end{Verbatim} @@ -699,6 +710,18 @@ ans = 0.666666666666667 + \end{Verbatim} + + \begin{Verbatim}[commandchars=\\\{\}] +{\color{incolor}In [{\color{incolor}36}]:} \PY{c}{\PYZpc{} determinant is (\PYZhy{}1)\PYZca{}(number\PYZus{}of\PYZus{}pivots)*diagonal\PYZus{}elements} + \PY{n+nb}{det}\PY{p}{(}\PY{n}{Ab}\PY{p}{)} + \PY{n}{Aug}\PY{p}{(}\PY{l+m+mi}{1}\PY{p}{,}\PY{l+m+mi}{1}\PY{p}{)}\PY{o}{*}\PY{n}{Aug}\PY{p}{(}\PY{l+m+mi}{2}\PY{p}{,}\PY{l+m+mi}{2}\PY{p}{)} +\end{Verbatim} + + \begin{Verbatim}[commandchars=\\\{\}] +ans = -3.0000 +ans = 3.0000 + \end{Verbatim} \subsubsection{Spring-Mass System again}\label{spring-mass-system-again} @@ -729,7 +752,7 @@ in matrix form: \(\left[ \begin{array}{cccc} k_1+k_2 & -k_2 & 0 & 0 \\ -k_2 & k_2+k_3 & -k_3 & 0 \\ 0 & -k_3 & k_3+k_4 & -k_4 \\ 0 & 0 & -k_4 & k_4 \end{array} \right] \left[ \begin{array}{c} x_{1} \\ x_{2} \\ x_{3} \\ x_{4} \end{array} \right]= \left[ \begin{array}{c} m_{1}g \\ m_{2}g \\ m_{3}g \\ m_{4}g \end{array} \right]\) \begin{Verbatim}[commandchars=\\\{\}] -{\color{incolor}In [{\color{incolor}29}]:} \PY{n}{k1}\PY{p}{=}\PY{l+m+mi}{10}\PY{p}{;} \PY{n}{k2}\PY{p}{=}\PY{l+m+mi}{5}\PY{p}{;}\PY{n}{k3}\PY{p}{=}\PY{l+m+mi}{2}\PY{p}{;}\PY{n}{k4}\PY{p}{=}\PY{l+m+mi}{1}\PY{p}{;} \PY{c}{\PYZpc{} N/m} +{\color{incolor}In [{\color{incolor}24}]:} \PY{n}{k1}\PY{p}{=}\PY{l+m+mi}{10}\PY{p}{;} \PY{n}{k2}\PY{p}{=}\PY{l+m+mi}{5}\PY{p}{;}\PY{n}{k3}\PY{p}{=}\PY{l+m+mi}{2}\PY{p}{;}\PY{n}{k4}\PY{p}{=}\PY{l+m+mi}{1}\PY{p}{;} \PY{c}{\PYZpc{} N/m} \PY{n}{m1}\PY{p}{=}\PY{l+m+mi}{1}\PY{p}{;} \PY{c}{\PYZpc{} kg} \PY{n}{m2}\PY{p}{=}\PY{l+m+mi}{2}\PY{p}{;} \PY{n}{m3}\PY{p}{=}\PY{l+m+mi}{3}\PY{p}{;} @@ -782,16 +805,17 @@ method & Number of Floating point operations for n\(\times\)n-matrix\tabularnewline \midrule \endhead -Naive Gauss & n-cubed\tabularnewline +Gauss & n-cubed\tabularnewline Tridiagonal & n\tabularnewline \bottomrule \end{longtable} \begin{Verbatim}[commandchars=\\\{\}] -{\color{incolor}In [{\color{incolor}30}]:} \PY{n+nb}{e}\PY{p}{=}\PY{p}{[}\PY{l+m+mi}{0}\PY{p}{;}\PY{o}{\PYZhy{}}\PY{l+m+mi}{5}\PY{p}{;}\PY{o}{\PYZhy{}}\PY{l+m+mi}{2}\PY{p}{;}\PY{o}{\PYZhy{}}\PY{l+m+mi}{1}\PY{p}{]}\PY{p}{;} +{\color{incolor}In [{\color{incolor}25}]:} \PY{n+nb}{e}\PY{p}{=}\PY{p}{[}\PY{l+m+mi}{0}\PY{p}{;}\PY{o}{\PYZhy{}}\PY{l+m+mi}{5}\PY{p}{;}\PY{o}{\PYZhy{}}\PY{l+m+mi}{2}\PY{p}{;}\PY{o}{\PYZhy{}}\PY{l+m+mi}{1}\PY{p}{]}\PY{p}{;} \PY{n}{g}\PY{p}{=}\PY{p}{[}\PY{o}{\PYZhy{}}\PY{l+m+mi}{5}\PY{p}{;}\PY{o}{\PYZhy{}}\PY{l+m+mi}{2}\PY{p}{;}\PY{o}{\PYZhy{}}\PY{l+m+mi}{1}\PY{p}{;}\PY{l+m+mi}{0}\PY{p}{]}\PY{p}{;} \PY{n}{f}\PY{p}{=}\PY{p}{[}\PY{l+m+mi}{15}\PY{p}{;}\PY{l+m+mi}{7}\PY{p}{;}\PY{l+m+mi}{3}\PY{p}{;}\PY{l+m+mi}{1}\PY{p}{]}\PY{p}{;} \PY{n}{Tridiag}\PY{p}{(}\PY{n+nb}{e}\PY{p}{,}\PY{n}{f}\PY{p}{,}\PY{n}{g}\PY{p}{,}\PY{n}{y}\PY{p}{)} + \PY{n}{K}\PY{o}{\PYZbs{}}\PY{n}{y} \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] @@ -799,11 +823,18 @@ ans = 9.8100 27.4680 61.8030 101.0430 +ans = + + 9.8100 + 27.4680 + 61.8030 + 101.0430 + \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] -{\color{incolor}In [{\color{incolor}12}]:} \PY{c}{\PYZpc{} tic ... t=toc } +{\color{incolor}In [{\color{incolor}26}]:} \PY{c}{\PYZpc{} tic ... t=toc } \PY{c}{\PYZpc{} is Matlab timer used for debugging programs} \PY{n}{t\PYZus{}GE} \PY{p}{=} \PY{n+nb}{zeros}\PY{p}{(}\PY{l+m+mi}{1}\PY{p}{,}\PY{l+m+mi}{100}\PY{p}{)}\PY{p}{;} \PY{n}{t\PYZus{}GE\PYZus{}tridiag} \PY{p}{=} \PY{n+nb}{zeros}\PY{p}{(}\PY{l+m+mi}{1}\PY{p}{,}\PY{l+m+mi}{100}\PY{p}{)}\PY{p}{;} @@ -820,7 +851,7 @@ ans = \PY{n}{x} \PY{p}{=} \PY{n}{GaussPivot}\PY{p}{(}\PY{n}{A}\PY{p}{,}\PY{n}{b}\PY{p}{)}\PY{p}{;} \PY{n}{t\PYZus{}GE}\PY{p}{(}\PY{n}{n}\PY{p}{)} \PY{p}{=} \PY{n+nb}{toc}\PY{p}{;} \PY{n+nb}{tic}\PY{p}{;} - \PY{n}{x} \PY{p}{=} \PY{n}{GaussPivot}\PY{p}{(}\PY{n}{Atd}\PY{p}{,}\PY{n}{b}\PY{p}{)}\PY{p}{;} + \PY{n}{x} \PY{p}{=} \PY{n}{A}\PY{o}{\PYZbs{}}\PY{n}{b}\PY{p}{;} \PY{n}{t\PYZus{}GE\PYZus{}tridiag}\PY{p}{(}\PY{n}{n}\PY{p}{)} \PY{p}{=} \PY{n+nb}{toc}\PY{p}{;} \PY{n+nb}{tic}\PY{p}{;} \PY{n}{x} \PY{p}{=} \PY{n}{Tridiag}\PY{p}{(}\PY{n+nb}{e}\PY{p}{,}\PY{n}{f}\PY{p}{,}\PY{n}{g}\PY{p}{,}\PY{n}{b}\PY{p}{)}\PY{p}{;} @@ -829,17 +860,67 @@ ans = \end{Verbatim} \begin{Verbatim}[commandchars=\\\{\}] -{\color{incolor}In [{\color{incolor}13}]:} \PY{n}{n}\PY{p}{=}\PY{l+m+mi}{1}\PY{p}{:}\PY{l+m+mi}{200}\PY{p}{;} +{\color{incolor}In [{\color{incolor}28}]:} \PY{n}{n}\PY{p}{=}\PY{l+m+mi}{1}\PY{p}{:}\PY{l+m+mi}{100}\PY{p}{;} \PY{n+nb}{loglog}\PY{p}{(}\PY{n}{n}\PY{p}{,}\PY{n}{t\PYZus{}GE}\PY{p}{,}\PY{n}{n}\PY{p}{,}\PY{n}{t\PYZus{}TD}\PY{p}{,}\PY{n}{n}\PY{p}{,}\PY{n}{t\PYZus{}GE\PYZus{}tridiag}\PY{p}{)} + \PY{n+nb}{legend}\PY{p}{(}\PY{l+s}{\PYZsq{}}\PY{l+s}{Gauss elim\PYZsq{}}\PY{p}{,}\PY{l+s}{\PYZsq{}}\PY{l+s}{Matlab \PYZbs{}\PYZsq{}}\PY{p}{,}\PY{l+s}{\PYZsq{}}\PY{l+s}{TriDiag\PYZsq{}}\PY{p}{)} \PY{n+nb}{xlabel}\PY{p}{(}\PY{l+s}{\PYZsq{}}\PY{l+s}{number of elements\PYZsq{}}\PY{p}{)} \PY{n+nb}{ylabel}\PY{p}{(}\PY{l+s}{\PYZsq{}}\PY{l+s}{time (s)\PYZsq{}}\PY{p}{)} \end{Verbatim} \begin{center} - \adjustimage{max size={0.9\linewidth}{0.9\paperheight}}{lecture_10_files/lecture_10_27_0.pdf} + \adjustimage{max size={0.9\linewidth}{0.9\paperheight}}{lecture_10_files/lecture_10_29_0.pdf} \end{center} { \hspace*{\fill} \\} + \begin{Verbatim}[commandchars=\\\{\}] +{\color{incolor}In [{\color{incolor}29}]:} \PY{p}{[}\PY{n}{x}\PY{p}{,}\PY{n}{Aug}\PY{p}{,}\PY{n}{npivots}\PY{p}{]}\PY{p}{=}\PY{n}{GaussPivot}\PY{p}{(}\PY{n}{K}\PY{p}{,}\PY{n}{y}\PY{p}{)} +\end{Verbatim} + + \begin{Verbatim}[commandchars=\\\{\}] +x = + + 9.8100 + 27.4680 + 61.8030 + 101.0430 + +Aug = + + 15.00000 -5.00000 0.00000 0.00000 9.81000 + 0.00000 5.33333 -2.00000 0.00000 22.89000 + 0.00000 0.00000 2.25000 -1.00000 38.01375 + 0.00000 0.00000 0.00000 0.55556 56.13500 + +npivots = 0 + + \end{Verbatim} + + \begin{Verbatim}[commandchars=\\\{\}] +{\color{incolor}In [{\color{incolor}30}]:} \PY{n}{A}\PY{p}{=}\PY{n}{Aug}\PY{p}{(}\PY{l+m+mi}{1}\PY{p}{:}\PY{l+m+mi}{4}\PY{p}{,}\PY{l+m+mi}{1}\PY{p}{:}\PY{l+m+mi}{4}\PY{p}{)} +\end{Verbatim} + + \begin{Verbatim}[commandchars=\\\{\}] +A = + + 15.00000 -5.00000 0.00000 0.00000 + 0.00000 5.33333 -2.00000 0.00000 + 0.00000 0.00000 2.25000 -1.00000 + 0.00000 0.00000 0.00000 0.55556 + + + \end{Verbatim} + + \begin{Verbatim}[commandchars=\\\{\}] +{\color{incolor}In [{\color{incolor}31}]:} \PY{n+nb}{det}\PY{p}{(}\PY{n}{A}\PY{p}{)} + \PY{n}{detA}\PY{p}{=}\PY{n}{A}\PY{p}{(}\PY{l+m+mi}{1}\PY{p}{,}\PY{l+m+mi}{1}\PY{p}{)}\PY{o}{*}\PY{n}{A}\PY{p}{(}\PY{l+m+mi}{2}\PY{p}{,}\PY{l+m+mi}{2}\PY{p}{)}\PY{o}{*}\PY{n}{A}\PY{p}{(}\PY{l+m+mi}{3}\PY{p}{,}\PY{l+m+mi}{3}\PY{p}{)}\PY{o}{*}\PY{n}{A}\PY{p}{(}\PY{l+m+mi}{4}\PY{p}{,}\PY{l+m+mi}{4}\PY{p}{)} +\end{Verbatim} + + \begin{Verbatim}[commandchars=\\\{\}] +ans = 100.00 +detA = 100.00 + + \end{Verbatim} + \begin{Verbatim}[commandchars=\\\{\}] {\color{incolor}In [{\color{incolor} }]:} \end{Verbatim} diff --git a/lecture_10/lecture_10_files/lecture_10_29_0.pdf b/lecture_10/lecture_10_files/lecture_10_29_0.pdf new file mode 100644 index 0000000..20bdd51 Binary files /dev/null and b/lecture_10/lecture_10_files/lecture_10_29_0.pdf differ diff --git a/lecture_10/lecture_10_files/lecture_10_29_0.svg b/lecture_10/lecture_10_files/lecture_10_29_0.svg new file mode 100644 index 0000000..eb8af2c --- /dev/null +++ b/lecture_10/lecture_10_files/lecture_10_29_0.svg @@ -0,0 +1,148 @@ + + +Gnuplot +Produced by GNUPLOT 5.0 patchlevel 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 10-5 + + + + + 10-4 + + + + + 10-3 + + + + + 10-2 + + + + + 10-1 + + + + + 100 + + + + + 100 + + + + + 101 + + + + + 102 + + + + + + + + + time (s) + + + + + number of elements + + + + + + + + + Gauss elim + + + + + Gauss elim + + + + + + Matlab \ + + + Matlab + + + + + + TriDiag + + + TriDiag + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lecture_10/lecture_10_files/lecture_10_6_0.pdf b/lecture_10/lecture_10_files/lecture_10_6_0.pdf new file mode 100644 index 0000000..53b6aa0 Binary files /dev/null and b/lecture_10/lecture_10_files/lecture_10_6_0.pdf differ diff --git a/lecture_10/lecture_10_files/lecture_10_6_0.svg b/lecture_10/lecture_10_files/lecture_10_6_0.svg new file mode 100644 index 0000000..73465c0 --- /dev/null +++ b/lecture_10/lecture_10_files/lecture_10_6_0.svg @@ -0,0 +1,397 @@ + + +Gnuplot +Produced by GNUPLOT 5.0 patchlevel 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -2 + + + + + + + + + + + -1.5 + + + + + + + + + + + -1 + + + + + + + + + + + -0.5 + + + + + + + + + + + 0 + + + + + + + + + + + 0.5 + + + + + + + + + + + 1 + + + + + + + + + + + 1.5 + + + + + + + + + + + 2 + + + + + + + + + + + -2 + + + + + + + + + + + -1.5 + + + + + + + + + + + -1 + + + + + + + + + + + -0.5 + + + + + + + + + + + 0 + + + + + + + + + + + 0.5 + + + + + + + + + + + 1 + + + + + + + + + + + 1.5 + + + + + + + + + + + 2 + + + + + + + + + + + -30 + + + + + + + + + + + + + -20 + + + + + + + + + + + + + -10 + + + + + + + + + + + + + 0 + + + + + + + + + + + + + 10 + + + + + + + + + + + + + 20 + + + + + + + + + + + + + 30 + + + + + + + x3 + + + + + gnuplot_plot_1a + + + + + + gnuplot_plot_2a + + + + gnuplot_plot_3a + + + + gnuplot_plot_4a + + + + + + + + + + + + + + + x1 + + + + + x2 + + + + + x3 + + + + + + \ No newline at end of file diff --git a/lecture_10/octave-workspace b/lecture_10/octave-workspace index ba49ea8..8a9aba2 100644 Binary files a/lecture_10/octave-workspace and b/lecture_10/octave-workspace differ