hw3: done 2 and 3, 1 still to transcribe

This commit is contained in:
Claudio Maggioni 2020-04-19 17:25:55 +02:00
parent 66d0710904
commit 84356b378a
3 changed files with 201 additions and 0 deletions

52
hw3/assignment3.m Normal file
View File

@ -0,0 +1,52 @@
%% Assignment 2
% Name: Claudio Maggioni
%
% Date: 19/3/2019
%
% This is a template file for the first assignment to get started with running
% and publishing code in Matlab. Each problem has its own section (delineated
% by |%%|) and can be run in isolation by clicking into the particular section
% and pressing |Ctrl| + |Enter| (evaluate current section).
%
% To generate a pdf for submission in your current directory, use the following
% three lines of code at the command window:
%
% >> options.format = 'pdf'; options.outputDir = pwd; publish('assignment2.m', options)
%
%% Problem 3
format rational
A = [4 3 2 1; 8 8 5 2; 16 12 10 5; 32 24 20 11];
[L,U,P] = pivotedOuterProductLU(A)
function [L,U,P] = pivotedOuterProductLU(A)
dimensions = size(A);
n = dimensions(1);
p = 1:n;
L = zeros(n);
U = zeros(n);
for i = 1:n
values = A(:,i);
values(values == 0) = -Inf;
[~, p_k] = max(values);
k = find(p == p_k);
p(k) = p(i);
p(i) = p_k;
L(:,i) = A(:,i) / A(p(i),i);
U(i,:) = A(p(i),:);
A = A - L(:,i) * U(i,:);
end
I = eye(n);
P = zeros(n);
for i = 1:n
P(:,i) = I(:,p(i));
end
P = transpose(P);
L
L = P * L;
end

BIN
hw3/hw3.pdf Normal file

Binary file not shown.

149
hw3/hw3.tex Normal file
View File

@ -0,0 +1,149 @@
% vim: set ts=2 sw=2 et tw=80:
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc} \usepackage[margin=2cm]{geometry}
\usepackage{amstext} \usepackage{amsmath} \usepackage{array}
\newcommand{\lra}{\Leftrightarrow}
\title{Howework 3 -- Introduction to Computational Science}
\author{Claudio Maggioni}
\begin{document} \maketitle
\section*{Question 1}
to be transcribed
\section*{Question 2}
\[i = 1 \hspace{1cm} k = 4 \hspace{1cm} \begin{bmatrix}4&2&3&1\\\end{bmatrix}\]
\[
l_1 =
\begin{bmatrix}
1/8 \\
1/4 \\
1/2 \\
1 \\
\end{bmatrix}
\hspace{1cm}
u_1 = \begin{bmatrix} 32 & 24 & 10 & 11\end{bmatrix}
\hspace{1cm}
\]\[
A_2 = \begin{bmatrix}4 &3 &2& 1\\ 8& 8& 5& 2\\ 16& 12& 10& 5\\ 32& 24& 20 &11 \\\end{bmatrix} - \begin{bmatrix}
4 & 3 & 5/2 & 11/8 \\
8 & 6 & 5 & 11/4 \\
16 & 12 & 10 & 11/2 \\
32 & 24 & 20 & 11 \\
\end{bmatrix} =
\begin{bmatrix}
0 & 0 & -1/2 & -3/8 \\
0 & 2 & 0 & -3/4 \\
0 & 0 & 0 & -1/2 \\
0 & 0 & 0 & 0 \\
\end{bmatrix}
\]
\[i = 2 \hspace{1cm} k = 2 \hspace{1cm} p = \begin{bmatrix}4&2&3&1\\\end{bmatrix}\]
\[
l_2 =\begin{bmatrix}
0\\1\\0\\0\\
\end{bmatrix}
\hspace{1cm}
u_2 =\begin{bmatrix} 0 & 2 & 0 & -3/4 \end{bmatrix}\]
\[
A_3 = \begin{bmatrix}
0 & 0 & -1/2 & -3/8 \\
0 & 2 & 0 & -3/4 \\
0 & 0 & 0 & -1/2 \\
0 & 0 & 0 & 0 \\
\end{bmatrix} -
\begin{bmatrix}
0 & 0 & 0 & 0 \\
0 & 2 & 0 & -3/4 \\
0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 \\
\end{bmatrix}
=
\begin{bmatrix}
0 & 0 & -1/2 & -3/8 \\
0 & 0 & 0 & 0 \\
0 & 0 & 0 & -1/2 \\
0 & 0 & 0 & 0 \\
\end{bmatrix}
\]
\[ i = 3 \hspace{1cm} k = 4 \hspace{1cm} p = \begin{bmatrix}
4&2&1&3\\
\end{bmatrix}
\]
\[
l_3 = \begin{bmatrix}
1 \\0\\0\\0\\
\end{bmatrix}
\hspace{1cm}
u_3 = \begin{bmatrix} 0 & 0& -1/2 & -3/8\\\end{bmatrix}
\]\[
A_4 = \begin{bmatrix}
0 & 0 & -1/2 & -3/8 \\
0 & 0 & 0 & 0 \\
0 & 0 & 0 & -1/2 \\
0 & 0 & 0 & 0 \\
\end{bmatrix} -
\begin{bmatrix}
0 & 0 & -1/2& -3/8\\
0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 \\
\end{bmatrix} =
\begin{bmatrix}
0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 \\
0 & 0 & 0 & -1/2 \\
0 & 0 & 0 & 0 \\
\end{bmatrix}
\]
\[ i =4 \hspace{1cm} k = 4 \hspace{1cm} p = \begin{bmatrix}
4&2&1&3\\
\end{bmatrix}\]
\[l_4 = \begin{bmatrix} 0 \\0\\1\\0\\\end{bmatrix}
u_4 = \begin{bmatrix}0&0&0&-1/2\end{bmatrix}
\]
\[
P =
\begin{bmatrix}
0 & 0 & 0 & 1 \\
0 & 1 & 0 & 0 \\
1 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 \\
\end{bmatrix}
\]
\[
L = P *
\begin{bmatrix}
1/8 & 0 & 1 & 0 \\
1/4 & 1 & 0 & 0 \\
1/2 & 0 & 0 & 1 \\
1 & 0 & 0 & 0 \\
\end{bmatrix}
=
\begin{bmatrix}
1 & 0 & 0 & 0 \\
1/4 & 1 & 0 & 0 \\
1/8 & 0 & 1 & 0 \\
1/2 & 0 & 0 & 1 \\
\end{bmatrix}
\]
\[
U =
\begin{bmatrix}
32 & 24 & 20 & 11 \\
0 & 2 & 0 & -3/4 \\
0 & 0 & -1/2 & -3/8 \\
0 & 0 & 0 & -1/2 \\
\end{bmatrix}
\]
\end{document}