Skip to content
Permalink
Newer
Older
100644 656 lines (493 sloc) 29.4 KB
Feb 23, 2017
1
2
% Default to the notebook output style
3
4
5
6
7
% Inherit from the specified cell style.
8
9
10
11
12
13
\documentclass[11pt]{article}
14
15
16
17
\usepackage[T1]{fontenc}
18
% Nicer default font (+ math font) than Computer Modern for most use cases
19
\usepackage{mathpazo}
20
21
% Basic figure setup, for now with no caption control since it's done
22
% automatically by Pandoc (which extracts ![](path) syntax from Markdown).
23
\usepackage{graphicx}
24
% We will generate all images so they have a width \maxwidth. This means
25
% that they will get their normal width if they fit onto the page, but
26
% are scaled down if they would overflow the margins.
27
\makeatletter
28
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
29
\else\Gin@nat@width\fi}
30
\makeatother
31
\let\Oldincludegraphics\includegraphics
32
% Set max figure width to be 80% of text width, for now hardcoded.
33
\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=.8\maxwidth]{#1}}
34
% Ensure that by default, figures have no caption (until we provide a
35
% proper Figure object with a Caption API and a way to capture that
36
% in the conversion process - todo).
37
\usepackage{caption}
38
\DeclareCaptionLabelFormat{nolabel}{}
39
\captionsetup{labelformat=nolabel}
40
41
\usepackage{adjustbox} % Used to constrain images to a maximum size
42
\usepackage{xcolor} % Allow colors to be defined
43
\usepackage{enumerate} % Needed for markdown enumerations to work
44
\usepackage{geometry} % Used to adjust the document margins
45
\usepackage{amsmath} % Equations
46
\usepackage{amssymb} % Equations
47
\usepackage{textcomp} % defines textquotesingle
48
% Hack from http://tex.stackexchange.com/a/47451/13684:
49
\AtBeginDocument{%
50
\def\PYZsq{\textquotesingle}% Upright quotes in Pygmentized code
51
}
52
\usepackage{upquote} % Upright quotes for verbatim code
53
\usepackage{eurosym} % defines \euro
54
\usepackage[mathletters]{ucs} % Extended unicode (utf-8) support
55
\usepackage[utf8x]{inputenc} % Allow utf-8 characters in the tex document
56
\usepackage{fancyvrb} % verbatim replacement that allows latex
57
\usepackage{grffile} % extends the file name processing of package graphics
58
% to support a larger range
59
% The hyperref package gives us a pdf with properly built
60
% internal navigation ('pdf bookmarks' for the table of contents,
61
% internal cross-reference links, web links for URLs, etc.)
62
\usepackage{hyperref}
63
\usepackage{longtable} % longtable support required by pandoc >1.10
64
\usepackage{booktabs} % table support for pandoc > 1.12.2
65
\usepackage[inline]{enumitem} % IRkernel/repr support (it uses the enumerate* environment)
66
\usepackage[normalem]{ulem} % ulem is needed to support strikethroughs (\sout)
67
% normalem makes italics be italics, not underlines
68
69
70
71
72
% Colors for the hyperref package
73
\definecolor{urlcolor}{rgb}{0,.145,.698}
74
\definecolor{linkcolor}{rgb}{.71,0.21,0.01}
75
\definecolor{citecolor}{rgb}{.12,.54,.11}
76
77
% ANSI colors
78
\definecolor{ansi-black}{HTML}{3E424D}
79
\definecolor{ansi-black-intense}{HTML}{282C36}
80
\definecolor{ansi-red}{HTML}{E75C58}
81
\definecolor{ansi-red-intense}{HTML}{B22B31}
82
\definecolor{ansi-green}{HTML}{00A250}
83
\definecolor{ansi-green-intense}{HTML}{007427}
84
\definecolor{ansi-yellow}{HTML}{DDB62B}
85
\definecolor{ansi-yellow-intense}{HTML}{B27D12}
86
\definecolor{ansi-blue}{HTML}{208FFB}
87
\definecolor{ansi-blue-intense}{HTML}{0065CA}
88
\definecolor{ansi-magenta}{HTML}{D160C4}
89
\definecolor{ansi-magenta-intense}{HTML}{A03196}
90
\definecolor{ansi-cyan}{HTML}{60C6C8}
91
\definecolor{ansi-cyan-intense}{HTML}{258F8F}
92
\definecolor{ansi-white}{HTML}{C5C1B4}
93
\definecolor{ansi-white-intense}{HTML}{A1A6B2}
94
95
% commands and environments needed by pandoc snippets
96
% extracted from the output of `pandoc -s`
97
\providecommand{\tightlist}{%
98
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
99
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
100
% Add ',fontsize=\small' for more characters per line
101
\newenvironment{Shaded}{}{}
102
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}}
103
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.56,0.13,0.00}{{#1}}}
104
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
105
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
106
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
107
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
108
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
109
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textit{{#1}}}}
110
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{{#1}}}
111
\newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}}
112
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.02,0.16,0.49}{{#1}}}
113
\newcommand{\RegionMarkerTok}[1]{{#1}}
114
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}}
115
\newcommand{\NormalTok}[1]{{#1}}
116
117
% Additional commands for more recent versions of Pandoc
118
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.53,0.00,0.00}{{#1}}}
119
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
120
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
121
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.73,0.40,0.53}{{#1}}}
122
\newcommand{\ImportTok}[1]{{#1}}
123
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.73,0.13,0.13}{\textit{{#1}}}}
124
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
125
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
126
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.10,0.09,0.49}{{#1}}}
127
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}}
128
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.40,0.40,0.40}{{#1}}}
129
\newcommand{\BuiltInTok}[1]{{#1}}
130
\newcommand{\ExtensionTok}[1]{{#1}}
131
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.74,0.48,0.00}{{#1}}}
132
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.49,0.56,0.16}{{#1}}}
133
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
134
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
135
136
137
% Define a nice break command that doesn't care if a line doesn't already
138
% exist.
139
\def\br{\hspace*{\fill} \\* }
140
% Math Jax compatability definitions
141
\def\gt{>}
142
\def\lt{<}
143
% Document parameters
144
\title{lecture\_11}
145
146
147
148
149
% Pygments definitions
150
151
\makeatletter
152
\def\PY@reset{\let\PY@it=\relax \let\PY@bf=\relax%
153
\let\PY@ul=\relax \let\PY@tc=\relax%
154
\let\PY@bc=\relax \let\PY@ff=\relax}
155
\def\PY@tok#1{\csname PY@tok@#1\endcsname}
156
\def\PY@toks#1+{\ifx\relax#1\empty\else%
157
\PY@tok{#1}\expandafter\PY@toks\fi}
158
\def\PY@do#1{\PY@bc{\PY@tc{\PY@ul{%
159
\PY@it{\PY@bf{\PY@ff{#1}}}}}}}
160
\def\PY#1#2{\PY@reset\PY@toks#1+\relax+\PY@do{#2}}
161
162
\expandafter\def\csname PY@tok@gd\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}}
163
\expandafter\def\csname PY@tok@gu\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}}
164
\expandafter\def\csname PY@tok@gt\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}}
165
\expandafter\def\csname PY@tok@gs\endcsname{\let\PY@bf=\textbf}
166
\expandafter\def\csname PY@tok@gr\endcsname{\def\PY@tc##1{\textcolor[rgb]{1.00,0.00,0.00}{##1}}}
167
\expandafter\def\csname PY@tok@cm\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
168
\expandafter\def\csname PY@tok@vg\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
169
\expandafter\def\csname PY@tok@vi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
170
\expandafter\def\csname PY@tok@mh\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
171
\expandafter\def\csname PY@tok@cs\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
172
\expandafter\def\csname PY@tok@ge\endcsname{\let\PY@it=\textit}
173
\expandafter\def\csname PY@tok@vc\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
174
\expandafter\def\csname PY@tok@il\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
175
\expandafter\def\csname PY@tok@go\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
176
\expandafter\def\csname PY@tok@cp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.74,0.48,0.00}{##1}}}
177
\expandafter\def\csname PY@tok@gi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.63,0.00}{##1}}}
178
\expandafter\def\csname PY@tok@gh\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}}
179
\expandafter\def\csname PY@tok@ni\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.60,0.60,0.60}{##1}}}
180
\expandafter\def\csname PY@tok@nl\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.63,0.63,0.00}{##1}}}
181
\expandafter\def\csname PY@tok@nn\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
182
\expandafter\def\csname PY@tok@no\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.53,0.00,0.00}{##1}}}
183
\expandafter\def\csname PY@tok@na\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.49,0.56,0.16}{##1}}}
184
\expandafter\def\csname PY@tok@nb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
185
\expandafter\def\csname PY@tok@nc\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
186
\expandafter\def\csname PY@tok@nd\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}}
187
\expandafter\def\csname PY@tok@ne\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.82,0.25,0.23}{##1}}}
188
\expandafter\def\csname PY@tok@nf\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
189
\expandafter\def\csname PY@tok@si\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}}
190
\expandafter\def\csname PY@tok@s2\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
191
\expandafter\def\csname PY@tok@nt\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
192
\expandafter\def\csname PY@tok@nv\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
193
\expandafter\def\csname PY@tok@s1\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
194
\expandafter\def\csname PY@tok@ch\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
195
\expandafter\def\csname PY@tok@m\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
196
\expandafter\def\csname PY@tok@gp\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}}
197
\expandafter\def\csname PY@tok@sh\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
198
\expandafter\def\csname PY@tok@ow\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}}
199
\expandafter\def\csname PY@tok@sx\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
200
\expandafter\def\csname PY@tok@bp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
201
\expandafter\def\csname PY@tok@c1\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
202
\expandafter\def\csname PY@tok@o\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
203
\expandafter\def\csname PY@tok@kc\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
204
\expandafter\def\csname PY@tok@c\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
205
\expandafter\def\csname PY@tok@mf\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
206
\expandafter\def\csname PY@tok@err\endcsname{\def\PY@bc##1{\setlength{\fboxsep}{0pt}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}
207
\expandafter\def\csname PY@tok@mb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
208
\expandafter\def\csname PY@tok@ss\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
209
\expandafter\def\csname PY@tok@sr\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}}
210
\expandafter\def\csname PY@tok@mo\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
211
\expandafter\def\csname PY@tok@kd\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
212
\expandafter\def\csname PY@tok@mi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
213
\expandafter\def\csname PY@tok@kn\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
214
\expandafter\def\csname PY@tok@cpf\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
215
\expandafter\def\csname PY@tok@kr\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
216
\expandafter\def\csname PY@tok@s\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
217
\expandafter\def\csname PY@tok@kp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
218
\expandafter\def\csname PY@tok@w\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}}
219
\expandafter\def\csname PY@tok@kt\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.69,0.00,0.25}{##1}}}
220
\expandafter\def\csname PY@tok@sc\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
221
\expandafter\def\csname PY@tok@sb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
222
\expandafter\def\csname PY@tok@k\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
223
\expandafter\def\csname PY@tok@se\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.13}{##1}}}
224
\expandafter\def\csname PY@tok@sd\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
225
226
\def\PYZbs{\char`\\}
227
\def\PYZus{\char`\_}
228
\def\PYZob{\char`\{}
229
\def\PYZcb{\char`\}}
230
\def\PYZca{\char`\^}
231
\def\PYZam{\char`\&}
232
\def\PYZlt{\char`\<}
233
\def\PYZgt{\char`\>}
234
\def\PYZsh{\char`\#}
235
\def\PYZpc{\char`\%}
236
\def\PYZdl{\char`\$}
237
\def\PYZhy{\char`\-}
238
\def\PYZsq{\char`\'}
239
\def\PYZdq{\char`\"}
240
\def\PYZti{\char`\~}
241
% for compatibility with earlier versions
242
\def\PYZat{@}
243
\def\PYZlb{[}
244
\def\PYZrb{]}
245
\makeatother
246
247
248
% Exact colors from NB
249
\definecolor{incolor}{rgb}{0.0, 0.0, 0.5}
250
\definecolor{outcolor}{rgb}{0.545, 0.0, 0.0}
251
252
253
254
255
% Prevent overflowing lines due to hard-to-break entities
256
\sloppy
257
% Setup hyperref package
258
\hypersetup{
259
breaklinks=true, % so long urls are correctly broken across lines
260
colorlinks=true,
261
urlcolor=urlcolor,
262
linkcolor=linkcolor,
263
citecolor=citecolor,
264
}
265
% Slightly bigger margins than the latex defaults
266
267
\geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in}
268
269
270
271
\begin{document}
272
273
274
\maketitle
275
276
277
278
279
\begin{Verbatim}[commandchars=\\\{\}]
280
{\color{incolor}In [{\color{incolor}18}]:} \PY{c}{\PYZpc{}plot \PYZhy{}\PYZhy{}format svg}
281
\end{Verbatim}
282
283
\begin{Verbatim}[commandchars=\\\{\}]
284
{\color{incolor}In [{\color{incolor}19}]:} \PY{n}{setdefaults}
285
\end{Verbatim}
286
287
\section{LU Decomposition}\label{lu-decomposition}
288
289
\subsubsection{efficient storage of matrices for
290
solutions}\label{efficient-storage-of-matrices-for-solutions}
291
292
Considering the same solution set:
293
294
\(y=Ax\)
295
296
Assume that we can perform Gauss elimination and achieve this formula:
297
298
\(Ux=d\)
299
300
Where, \(U\) is an upper triangular matrix that we derived from Gauss
301
elimination and \(d\) is the set of dependent variables after Gauss
302
elimination.
303
304
Assume there is a lower triangular matrix, \(L\), with ones on the
305
diagonal and same dimensions of \(U\) and the following is true:
306
307
\(L(Ux-d)=Ax-y=0\)
308
309
Now, \(Ax=LUx\), so \(A=LU\), and \(y=Ld\).
310
311
\(2x_{1}+x_{2}=1\)
312
313
\(x_{1}+3x_{2}=1\)
314
315
\(\left[ \begin{array}{cc} 2 & 1 \\ 1 & 3 \end{array} \right] \left[\begin{array}{c} x_{1} \\ x_{2} \end{array}\right]= \left[\begin{array}{c} 1 \\ 1\end{array}\right]\)
316
317
f21=0.5
318
319
A(2,1)=1-1 = 0
320
321
A(2,2)=3-0.5=2.5
322
323
y(2)=1-0.5=0.5
324
325
\(L(Ux-d)= \left[ \begin{array}{cc} 1 & 0 \\ 0.5 & 1 \end{array} \right] \left(\left[ \begin{array}{cc} 2 & 1 \\ 0 & 2.5 \end{array} \right] \left[\begin{array}{c} x_{1} \\ x_{2} \end{array}\right]- \left[\begin{array}{c} 1 \\ 0.5\end{array}\right]\right)=0\)
326
327
\begin{Verbatim}[commandchars=\\\{\}]
328
{\color{incolor}In [{\color{incolor}3}]:} \PY{n}{A}\PY{p}{=}\PY{p}{[}\PY{l+m+mi}{2}\PY{p}{,}\PY{l+m+mi}{1}\PY{p}{;}\PY{l+m+mi}{1}\PY{p}{,}\PY{l+m+mi}{3}\PY{p}{]}
329
\PY{n}{L}\PY{p}{=}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{,}\PY{l+m+mi}{0}\PY{p}{;}\PY{l+m+mf}{0.5}\PY{p}{,}\PY{l+m+mi}{1}\PY{p}{]}
330
\PY{n}{U}\PY{p}{=}\PY{p}{[}\PY{l+m+mi}{2}\PY{p}{,}\PY{l+m+mi}{1}\PY{p}{;}\PY{l+m+mi}{0}\PY{p}{,}\PY{l+m+mf}{2.5}\PY{p}{]}
331
\PY{n}{L}\PY{o}{*}\PY{n}{U}
332
333
\PY{n}{d}\PY{p}{=}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{;}\PY{l+m+mf}{0.5}\PY{p}{]}
334
\PY{n}{y}\PY{p}{=}\PY{n}{L}\PY{o}{*}\PY{n}{d}
335
\end{Verbatim}
336
337
\begin{Verbatim}[commandchars=\\\{\}]
338
A =
339
340
2 1
341
1 3
342
343
L =
344
345
1.00000 0.00000
346
0.50000 1.00000
347
348
U =
349
350
2.00000 1.00000
351
0.00000 2.50000
352
353
ans =
354
355
2 1
356
1 3
357
358
d =
359
360
1.00000
361
0.50000
362
363
y =
364
365
1
366
1
367
368
369
\end{Verbatim}
370
371
\subsection{Pivoting for LU
372
factorization}\label{pivoting-for-lu-factorization}
373
374
LU factorization uses the same method as Gauss elimination so it is also
375
necessary to perform partial pivoting when creating the lower and upper
376
triangular matrices.
377
378
Matlab and Octave use pivoting in the command
379
380
\texttt{{[}L,U,P{]}=lu(A)}
381
382
\begin{Verbatim}[commandchars=\\\{\}]
383
{\color{incolor}In [{\color{incolor}4}]:} \PY{n}{help} \PY{n+nb}{lu}
384
\end{Verbatim}
385
386
\begin{Verbatim}[commandchars=\\\{\}]
387
'lu' is a built-in function from the file libinterp/corefcn/lu.cc
388
389
-- Built-in Function: [L, U] = lu (A)
390
-- Built-in Function: [L, U, P] = lu (A)
391
-- Built-in Function: [L, U, P, Q] = lu (S)
392
-- Built-in Function: [L, U, P, Q, R] = lu (S)
393
-- Built-in Function: [{\ldots}] = lu (S, THRES)
394
-- Built-in Function: Y = lu ({\ldots})
395
-- Built-in Function: [{\ldots}] = lu ({\ldots}, "vector")
396
Compute the LU decomposition of A.
397
398
If A is full subroutines from LAPACK are used and if A is sparse
399
then UMFPACK is used.
400
401
The result is returned in a permuted form, according to the
402
optional return value P. For example, given the matrix 'a = [1, 2;
403
3, 4]',
404
405
[l, u, p] = lu (A)
406
407
returns
408
409
l =
410
411
1.00000 0.00000
412
0.33333 1.00000
413
414
u =
415
416
3.00000 4.00000
417
0.00000 0.66667
418
419
p =
420
421
0 1
422
1 0
423
424
The matrix is not required to be square.
425
426
When called with two or three output arguments and a spare input
427
matrix, 'lu' does not attempt to perform sparsity preserving column
428
permutations. Called with a fourth output argument, the sparsity
429
preserving column transformation Q is returned, such that 'P * A *
430
Q = L * U'.
431
432
Called with a fifth output argument and a sparse input matrix, 'lu'
433
attempts to use a scaling factor R on the input matrix such that 'P
434
* (R \textbackslash{} A) * Q = L * U'. This typically leads to a sparser and more
435
stable factorization.
436
437
An additional input argument THRES, that defines the pivoting
438
threshold can be given. THRES can be a scalar, in which case it
439
defines the UMFPACK pivoting tolerance for both symmetric and
440
unsymmetric cases. If THRES is a 2-element vector, then the first
441
element defines the pivoting tolerance for the unsymmetric UMFPACK
442
pivoting strategy and the second for the symmetric strategy. By
443
default, the values defined by 'spparms' are used ([0.1, 0.001]).
444
445
Given the string argument "vector", 'lu' returns the values of P
446
and Q as vector values, such that for full matrix, 'A (P,:) = L *
447
U', and 'R(P,:) * A (:, Q) = L * U'.
448
449
With two output arguments, returns the permuted forms of the upper
450
and lower triangular matrices, such that 'A = L * U'. With one
451
output argument Y, then the matrix returned by the LAPACK routines
452
is returned. If the input matrix is sparse then the matrix L is
453
embedded into U to give a return value similar to the full case.
454
For both full and sparse matrices, 'lu' loses the permutation
455
information.
456
457
See also: luupdate, ilu, chol, hess, qr, qz, schur, svd.
458
459
Additional help for built-in functions and operators is
460
available in the online version of the manual. Use the command
461
'doc <topic>' to search the manual index.
462
463
Help and information about Octave is also available on the WWW
464
at http://www.octave.org and via the help@octave.org
465
mailing list.
466
467
\end{Verbatim}
468
469
\begin{Verbatim}[commandchars=\\\{\}]
470
{\color{incolor}In [{\color{incolor}22}]:} \PY{c}{\PYZpc{} time LU solution vs backslash}
471
\PY{n}{t\PYZus{}lu}\PY{p}{=}\PY{n+nb}{zeros}\PY{p}{(}\PY{l+m+mi}{100}\PY{p}{,}\PY{l+m+mi}{1}\PY{p}{)}\PY{p}{;}
472
\PY{n}{t\PYZus{}bs}\PY{p}{=}\PY{n+nb}{zeros}\PY{p}{(}\PY{l+m+mi}{100}\PY{p}{,}\PY{l+m+mi}{1}\PY{p}{)}\PY{p}{;}
473
\PY{k}{for} \PY{n}{N}\PY{p}{=}\PY{l+m+mi}{1}\PY{p}{:}\PY{l+m+mi}{100}
474
\PY{n}{A}\PY{p}{=}\PY{n+nb}{rand}\PY{p}{(}\PY{n}{N}\PY{p}{,}\PY{n}{N}\PY{p}{)}\PY{p}{;}
475
\PY{n}{y}\PY{p}{=}\PY{n+nb}{rand}\PY{p}{(}\PY{n}{N}\PY{p}{,}\PY{l+m+mi}{1}\PY{p}{)}\PY{p}{;}
476
\PY{p}{[}\PY{n}{L}\PY{p}{,}\PY{n}{U}\PY{p}{,}\PY{n}{P}\PY{p}{]}\PY{p}{=}\PY{n+nb}{lu}\PY{p}{(}\PY{n}{A}\PY{p}{)}\PY{p}{;}
477
478
\PY{n+nb}{tic}\PY{p}{;} \PY{n}{d}\PY{p}{=}\PY{n}{L}\PY{o}{\PYZbs{}}\PY{n}{y}\PY{p}{;} \PY{n}{x}\PY{p}{=}\PY{n}{U}\PY{o}{\PYZbs{}}\PY{n}{d}\PY{p}{;} \PY{n}{t\PYZus{}lu}\PY{p}{(}\PY{n}{N}\PY{p}{)}\PY{p}{=}\PY{n+nb}{toc}\PY{p}{;}
479
480
\PY{n+nb}{tic}\PY{p}{;} \PY{n}{x}\PY{p}{=}\PY{n}{A}\PY{o}{\PYZbs{}}\PY{n}{y}\PY{p}{;} \PY{n}{t\PYZus{}bs}\PY{p}{(}\PY{n}{N}\PY{p}{)}\PY{p}{=}\PY{n+nb}{toc}\PY{p}{;}
481
\PY{k}{end}
482
\PY{n+nb}{plot}\PY{p}{(}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{:}\PY{l+m+mi}{100}\PY{p}{]}\PY{p}{,}\PY{n}{t\PYZus{}lu}\PY{p}{,}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{:}\PY{l+m+mi}{100}\PY{p}{]}\PY{p}{,}\PY{n}{t\PYZus{}bs}\PY{p}{)}
483
\PY{n+nb}{legend}\PY{p}{(}\PY{l+s}{\PYZsq{}}\PY{l+s}{LU decomp\PYZsq{}}\PY{p}{,}\PY{l+s}{\PYZsq{}}\PY{l+s}{Octave \PYZbs{}\PYZbs{}\PYZsq{}}\PY{p}{)}
484
\end{Verbatim}
485
486
\begin{center}
487
\adjustimage{max size={0.9\linewidth}{0.9\paperheight}}{lecture_11_files/lecture_11_6_0.pdf}
488
\end{center}
489
{ \hspace*{\fill} \\}
490
491
Consider the problem again from the intro to Linear Algebra, 4 masses
492
are connected in series to 4 springs with K=10 N/m. What are the final
493
positions of the masses?
494
495
\begin{figure}[htbp]
496
\centering
497
\includegraphics{mass_springs.png}
498
\caption{Springs-masses}
499
\end{figure}
500
501
The masses haves the following amounts, 1, 2, 3, and 4 kg for masses
502
1-4. Using a FBD for each mass:
503
504
\(m_{1}g+k(x_{2}-x_{1})-kx_{1}=0\)
505
506
\(m_{2}g+k(x_{3}-x_{2})-k(x_{2}-x_{1})=0\)
507
508
\(m_{3}g+k(x_{4}-x_{3})-k(x_{3}-x_{2})=0\)
509
510
\(m_{4}g-k(x_{4}-x_{3})=0\)
511
512
in matrix form:
513
514
\(\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]\)
515
516
\begin{Verbatim}[commandchars=\\\{\}]
517
{\color{incolor}In [{\color{incolor}24}]:} \PY{n}{k}\PY{p}{=}\PY{l+m+mi}{10}\PY{p}{;} \PY{c}{\PYZpc{} N/m}
518
\PY{n}{m1}\PY{p}{=}\PY{l+m+mi}{1}\PY{p}{;} \PY{c}{\PYZpc{} kg}
519
\PY{n}{m2}\PY{p}{=}\PY{l+m+mi}{2}\PY{p}{;}
520
\PY{n}{m3}\PY{p}{=}\PY{l+m+mi}{3}\PY{p}{;}
521
\PY{n}{m4}\PY{p}{=}\PY{l+m+mi}{4}\PY{p}{;}
522
\PY{n}{g}\PY{p}{=}\PY{l+m+mf}{9.81}\PY{p}{;} \PY{c}{\PYZpc{} m/s\PYZca{}2}
523
\PY{n}{K}\PY{p}{=}\PY{p}{[}\PY{l+m+mi}{2}\PY{o}{*}\PY{n}{k} \PY{o}{\PYZhy{}}\PY{n}{k} \PY{l+m+mi}{0} \PY{l+m+mi}{0}\PY{p}{;} \PY{o}{\PYZhy{}}\PY{n}{k} \PY{l+m+mi}{2}\PY{o}{*}\PY{n}{k} \PY{o}{\PYZhy{}}\PY{n}{k} \PY{l+m+mi}{0}\PY{p}{;} \PY{l+m+mi}{0} \PY{o}{\PYZhy{}}\PY{n}{k} \PY{l+m+mi}{2}\PY{o}{*}\PY{n}{k} \PY{o}{\PYZhy{}}\PY{n}{k}\PY{p}{;} \PY{l+m+mi}{0} \PY{l+m+mi}{0} \PY{o}{\PYZhy{}}\PY{n}{k} \PY{n}{k}\PY{p}{]}
524
\PY{n}{y}\PY{p}{=}\PY{p}{[}\PY{n}{m1}\PY{o}{*}\PY{n}{g}\PY{p}{;}\PY{n}{m2}\PY{o}{*}\PY{n}{g}\PY{p}{;}\PY{n}{m3}\PY{o}{*}\PY{n}{g}\PY{p}{;}\PY{n}{m4}\PY{o}{*}\PY{n}{g}\PY{p}{]}
525
\end{Verbatim}
526
527
\begin{Verbatim}[commandchars=\\\{\}]
528
K =
529
530
20 -10 0 0
531
-10 20 -10 0
532
0 -10 20 -10
533
0 0 -10 10
534
535
y =
536
537
9.8100
538
19.6200
539
29.4300
540
39.2400
541
542
543
\end{Verbatim}
544
545
This matrix, K, is symmetric.
546
547
\texttt{K(i,j)==K(j,i)}
548
549
Now we can use,
550
551
\subsection{Cholesky Factorization}\label{cholesky-factorization}
552
553
We can decompose the matrix, K into two matrices, \(U\) and \(U^{T}\),
554
where
555
556
\(K=U^{T}U\)
557
558
each of the components of U can be calculated with the following
559
equations:
560
561
\(u_{ii}=\sqrt{a_{ii}-\sum_{k=1}^{i-1}u_{ki}^{2}}\)
562
563
\(u_{ij}=\frac{a_{ij}-\sum_{k=1}^{i-1}u_{ki}u_{kj}}{u_{ii}}\)
564
565
so for K
566
567
\begin{Verbatim}[commandchars=\\\{\}]
568
{\color{incolor}In [{\color{incolor}25}]:} \PY{n}{K}
569
\end{Verbatim}
570
571
\begin{Verbatim}[commandchars=\\\{\}]
572
K =
573
574
20 -10 0 0
575
-10 20 -10 0
576
0 -10 20 -10
577
0 0 -10 10
578
579
580
\end{Verbatim}
581
582
\begin{Verbatim}[commandchars=\\\{\}]
583
{\color{incolor}In [{\color{incolor}26}]:} \PY{n}{u11}\PY{p}{=}\PY{n+nb}{sqrt}\PY{p}{(}\PY{n}{K}\PY{p}{(}\PY{l+m+mi}{1}\PY{p}{,}\PY{l+m+mi}{1}\PY{p}{)}\PY{p}{)}
584
\PY{n}{u12}\PY{p}{=}\PY{p}{(}\PY{n}{K}\PY{p}{(}\PY{l+m+mi}{1}\PY{p}{,}\PY{l+m+mi}{2}\PY{p}{)}\PY{p}{)}\PY{o}{/}\PY{n}{u11}
585
\PY{n}{u13}\PY{p}{=}\PY{p}{(}\PY{n}{K}\PY{p}{(}\PY{l+m+mi}{1}\PY{p}{,}\PY{l+m+mi}{3}\PY{p}{)}\PY{p}{)}\PY{o}{/}\PY{n}{u11}
586
\PY{n}{u14}\PY{p}{=}\PY{p}{(}\PY{n}{K}\PY{p}{(}\PY{l+m+mi}{1}\PY{p}{,}\PY{l+m+mi}{4}\PY{p}{)}\PY{p}{)}\PY{o}{/}\PY{n}{u11}
587
\PY{n}{u22}\PY{p}{=}\PY{n+nb}{sqrt}\PY{p}{(}\PY{n}{K}\PY{p}{(}\PY{l+m+mi}{2}\PY{p}{,}\PY{l+m+mi}{2}\PY{p}{)}\PY{o}{\PYZhy{}}\PY{n}{u12}\PYZca{}\PY{l+m+mi}{2}\PY{p}{)}
588
\PY{n}{u23}\PY{p}{=}\PY{p}{(}\PY{n}{K}\PY{p}{(}\PY{l+m+mi}{2}\PY{p}{,}\PY{l+m+mi}{3}\PY{p}{)}\PY{o}{\PYZhy{}}\PY{n}{u12}\PY{o}{*}\PY{n}{u13}\PY{p}{)}\PY{o}{/}\PY{n}{u22}
589
\PY{n}{u24}\PY{p}{=}\PY{p}{(}\PY{n}{K}\PY{p}{(}\PY{l+m+mi}{2}\PY{p}{,}\PY{l+m+mi}{4}\PY{p}{)}\PY{o}{\PYZhy{}}\PY{n}{u12}\PY{o}{*}\PY{n}{u14}\PY{p}{)}\PY{o}{/}\PY{n}{u22}
590
\PY{n}{u33}\PY{p}{=}\PY{n+nb}{sqrt}\PY{p}{(}\PY{n}{K}\PY{p}{(}\PY{l+m+mi}{3}\PY{p}{,}\PY{l+m+mi}{3}\PY{p}{)}\PY{o}{\PYZhy{}}\PY{n}{u13}\PYZca{}\PY{l+m+mi}{2}\PY{o}{\PYZhy{}}\PY{n}{u23}\PYZca{}\PY{l+m+mi}{2}\PY{p}{)}
591
\PY{n}{u34}\PY{p}{=}\PY{p}{(}\PY{n}{K}\PY{p}{(}\PY{l+m+mi}{3}\PY{p}{,}\PY{l+m+mi}{4}\PY{p}{)}\PY{o}{\PYZhy{}}\PY{n}{u13}\PY{o}{*}\PY{n}{u14}\PY{o}{\PYZhy{}}\PY{n}{u23}\PY{o}{*}\PY{n}{u24}\PY{p}{)}\PY{o}{/}\PY{n}{u33}
592
\PY{n}{u44}\PY{p}{=}\PY{n+nb}{sqrt}\PY{p}{(}\PY{n}{K}\PY{p}{(}\PY{l+m+mi}{4}\PY{p}{,}\PY{l+m+mi}{4}\PY{p}{)}\PY{o}{\PYZhy{}}\PY{n}{u14}\PYZca{}\PY{l+m+mi}{2}\PY{o}{\PYZhy{}}\PY{n}{u24}\PYZca{}\PY{l+m+mi}{2}\PY{o}{\PYZhy{}}\PY{n}{u34}\PYZca{}\PY{l+m+mi}{2}\PY{p}{)}
593
\PY{n}{U}\PY{p}{=}\PY{p}{[}\PY{n}{u11}\PY{p}{,}\PY{n}{u12}\PY{p}{,}\PY{n}{u13}\PY{p}{,}\PY{n}{u14}\PY{p}{;}\PY{l+m+mi}{0}\PY{p}{,}\PY{n}{u22}\PY{p}{,}\PY{n}{u23}\PY{p}{,}\PY{n}{u24}\PY{p}{;}\PY{l+m+mi}{0}\PY{p}{,}\PY{l+m+mi}{0}\PY{p}{,}\PY{n}{u33}\PY{p}{,}\PY{n}{u34}\PY{p}{;}\PY{l+m+mi}{0}\PY{p}{,}\PY{l+m+mi}{0}\PY{p}{,}\PY{l+m+mi}{0}\PY{p}{,}\PY{n}{u44}\PY{p}{]}
594
\end{Verbatim}
595
596
\begin{Verbatim}[commandchars=\\\{\}]
597
u11 = 4.4721
598
u12 = -2.2361
599
u13 = 0
600
u14 = 0
601
u22 = 3.8730
602
u23 = -2.5820
603
u24 = 0
604
u33 = 3.6515
605
u34 = -2.7386
606
u44 = 1.5811
607
U =
608
609
4.47214 -2.23607 0.00000 0.00000
610
0.00000 3.87298 -2.58199 0.00000
611
0.00000 0.00000 3.65148 -2.73861
612
0.00000 0.00000 0.00000 1.58114
613
614
615
\end{Verbatim}
616
617
\begin{Verbatim}[commandchars=\\\{\}]
618
{\color{incolor}In [{\color{incolor}27}]:} \PY{n}{U}\PY{o}{\PYZsq{}}\PY{o}{*}\PY{n}{U}
619
\end{Verbatim}
620
621
\begin{Verbatim}[commandchars=\\\{\}]
622
ans =
623
624
20.00000 -10.00000 0.00000 0.00000
625
-10.00000 20.00000 -10.00000 0.00000
626
0.00000 -10.00000 20.00000 -10.00000
627
0.00000 0.00000 -10.00000 10.00000
628
629
630
\end{Verbatim}
631
632
\begin{Verbatim}[commandchars=\\\{\}]
633
{\color{incolor}In [{\color{incolor}37}]:} \PY{c}{\PYZpc{} time solution for Cholesky vs backslash}
634
\PY{n}{t\PYZus{}chol}\PY{p}{=}\PY{n+nb}{zeros}\PY{p}{(}\PY{l+m+mi}{1000}\PY{p}{,}\PY{l+m+mi}{1}\PY{p}{)}\PY{p}{;}
635
\PY{n}{t\PYZus{}bs}\PY{p}{=}\PY{n+nb}{zeros}\PY{p}{(}\PY{l+m+mi}{1000}\PY{p}{,}\PY{l+m+mi}{1}\PY{p}{)}\PY{p}{;}
636
\PY{k}{for} \PY{n}{i}\PY{p}{=}\PY{l+m+mi}{1}\PY{p}{:}\PY{l+m+mi}{1000}
637
\PY{n+nb}{tic}\PY{p}{;} \PY{n}{d}\PY{p}{=}\PY{n}{U}\PY{o}{\PYZsq{}}\PY{o}{*}\PY{n}{y}\PY{p}{;} \PY{n}{x}\PY{p}{=}\PY{n}{U}\PY{o}{\PYZbs{}}\PY{n}{d}\PY{p}{;} \PY{n}{t\PYZus{}chol}\PY{p}{(}\PY{n}{i}\PY{p}{)}\PY{p}{=}\PY{n+nb}{toc}\PY{p}{;}
638
\PY{n+nb}{tic}\PY{p}{;} \PY{n}{x}\PY{p}{=}\PY{n}{K}\PY{o}{\PYZbs{}}\PY{n}{y}\PY{p}{;} \PY{n}{t\PYZus{}bs}\PY{p}{(}\PY{n}{i}\PY{p}{)}\PY{p}{=}\PY{n+nb}{toc}\PY{p}{;}
639
\PY{k}{end}
640
\PY{n+nb}{fprintf}\PY{p}{(}\PY{l+s}{\PYZsq{}}\PY{l+s}{average time spent for Cholesky factored solution = \PYZpc{}e+/\PYZhy{}\PYZpc{}e\PYZsq{}}\PY{p}{,}\PY{n+nb}{mean}\PY{p}{(}\PY{n}{t\PYZus{}chol}\PY{p}{)}\PY{p}{,}\PY{n+nb}{std}\PY{p}{(}\PY{n}{t\PYZus{}chol}\PY{p}{)}\PY{p}{)}
641
642
\PY{n+nb}{fprintf}\PY{p}{(}\PY{l+s}{\PYZsq{}}\PY{l+s}{average time spent for backslash solution = \PYZpc{}e+/\PYZhy{}\PYZpc{}e\PYZsq{}}\PY{p}{,}\PY{n+nb}{mean}\PY{p}{(}\PY{n}{t\PYZus{}bs}\PY{p}{)}\PY{p}{,}\PY{n+nb}{std}\PY{p}{(}\PY{n}{t\PYZus{}bs}\PY{p}{)}\PY{p}{)}
643
\end{Verbatim}
644
645
\begin{Verbatim}[commandchars=\\\{\}]
646
average time spent for Cholesky factored solution = 1.623154e-05+/-1.166726e-05
647
average time spent for backslash solution = 1.675844e-05+/-1.187234e-05
648
649
\end{Verbatim}
650
651
652
% Add a bibliography block to the postdoc
653
654
655
656
\end{document}
You can’t perform that action at this time.