]> git.rustad.me Git - nummat1/commitdiff
Initial commit of report and its python files
authorBjørn Rustad <rustadbjornen@gmail.com>
Thu, 29 Sep 2011 08:58:36 +0000 (10:58 +0200)
committerBjørn Rustad <rustadbjornen@gmail.com>
Thu, 29 Sep 2011 08:58:36 +0000 (10:58 +0200)
bj_function.py [new file with mode: 0644]
rapport.tex [new file with mode: 0644]

diff --git a/bj_function.py b/bj_function.py
new file mode 100644 (file)
index 0000000..6eb99fd
--- /dev/null
@@ -0,0 +1,11 @@
+# Calculate function value in point x
+def function_g(x, H, b, c):
+    return -b.T.dot(x) + 0.5 * x.T.dot(H.dot(x)) + (1.0/12.0) * x.T.dot(_C(x,c).dot(x))
+
+# Calculate gradient of g in point x
+def gradient_g(x, H, b, c):
+    return -b.T + H.dot(x) + (1.0/3.0) * x.T.dot(_C(x,c))
+
+# Calculate hessian of g in point x
+def hessian_g(x, H, b, c):
+    return  H + _C(x,c)
diff --git a/rapport.tex b/rapport.tex
new file mode 100644 (file)
index 0000000..f8f2734
--- /dev/null
@@ -0,0 +1,127 @@
+% Fag: Numerisk matematikk \r
+% Project 1\r
+% Utført av: Bjørn, Mats og Edvard\r
+\r
+\documentclass[12pt, a4paper]{article}\r
+\usepackage[norsk]{babel}\r
+\usepackage[latin1]{inputenc}\r
+\usepackage{listings}\r
+\usepackage{graphicx}\r
+\usepackage{color}\r
+\usepackage{amssymb, amsmath}\r
+\setcounter{secnumdepth}{0}\r
+\setlength{\textheight}{240mm} \r
+\setlength{\textwidth}{150mm}  \r
+\topmargin -5mm \r
+\oddsidemargin 5mm\r
+\r
+\definecolor{orange}{rgb}{1,0.5,0}\r
+\r
+\lstset{ %\r
+language=Python,                % the language of the code\r
+basicstyle=\footnotesize,       % the size of the fonts that are used for the code\r
+numbers=left,                   % where to put the line-numbers\r
+numberstyle=\footnotesize,      % the size of the fonts that are used for the line-numbers\r
+stepnumber=1,                   % the step between two line-numbers. If it's 1, each line \r
+                                % will be numbered\r
+numbersep=5pt,                  % how far the line-numbers are from the code\r
+backgroundcolor=\color{white},  % choose the background color. You must add \usepackage{color}\r
+%showspaces=false,               % show spaces adding particular underscores\r
+%showstringspaces=false,         % underline spaces within strings\r
+%showtabs=false,                 % show tabs within strings adding particular underscores\r
+%frame=single,                   % adds a frame around the code\r
+tabsize=4,                      % sets default tabsize to 2 spaces\r
+captionpos=b,                   % sets the caption-position to bottom\r
+breaklines=true,                % sets automatic line breaking\r
+%breakatwhitespace=false,        % sets if automatic breaks should only happen at whitespace\r
+%title=\lstname,                 % show the filename of files included with \lstinputlisting;\r
+                                % also try caption instead of title\r
+%escapeinside={\%*}{*)},         % if you want to add a comment within your code\r
+%morekeywords={*,...}            % if you want to add more keywords to the set\r
+keywordstyle=\color{orange}\bfseries\emph\r
+}\r
+\r
+\begin{document}\r
+\r
+\title{Semester Project 1 TMA4215}\r
+\author{\r
+       KANDIDATNUMMER! \footnote{Skriv noe her.} \\\r
+       Hva med noe her også?\r
+}\r
+\r
+\maketitle\r
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
+%                                %\r
+%        SAMMENDRAG              %\r
+%                                %\r
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
+\abstract{\r
+ABSTRACTABSTBSSTRACTABSTRACTABSTRACT\r
+}\r
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
+%                                %\r
+%        RESULTATER              %\r
+%                                %\r
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r
+\section{Resultater}\r
+We used the following data:\r
+\begin{equation}\r
+H = \r
+\begin{bmatrix}\r
+1 & 2 \\\r
+3 & 4 \r
+\end{bmatrix}\r
+,  \mathbf{b} =\r
+\begin{bmatrix}\r
+1 \\\r
+2\r
+\end{bmatrix}\r
+,  \mathbf{c} =\r
+\begin{bmatrix}\r
+1 \\\r
+2\r
+\end{bmatrix}.\r
+\end{equation}\r
+Where the elements of $\mathbf{b}$ are randomly generated numbers from the interval INTERVAL, and the elements of $\mathbf{c}$ are randomly generated positive numbers.\r
+\r
+To generate the nxn matrix, $H$, we first generate a upper triangular nxn matrix $U$.\r
+The elements along the diagonal of $U$ are the square roots of randomly generated positive numbers, and the elements above the diagonal are randomly generated numbers from the interval INTERVAL.\r
+$H = U^{T}U$ is then a symmetric positive definite matrix.\r
+\r
+The function analyzed in this project was\r
+\r
+\begin{equation}\r
+\label{eq:func_g}\r
+g(\mathbf{x}) := -\mathbf{b}^{T}\mathbf{x}+\frac{1}{2}\mathbf{x}^{T}H\mathbf{x}+\frac{1}{12}\mathbf{x}^{T}C(\mathbf{x})\mathbf{x}\r
+\end{equation}\r
+\r
+From equation \ref{eq:func_g} we get\r
+\r
+\begin{equation}\r
+\label{eq:grad_g}\r
+\nabla g(\mathbf{x}) = -\mathbf{b}^{T}+H\mathbf{x}+\frac{1}{3}\mathbf{x}^{T}C(\mathbf{x}),\r
+\end{equation}\r
+\begin{equation}\r
+\label{eq:hess_g}\r
+\nabla^{2}g(\mathbf{x}) = H+C(\mathbf{x}).\r
+\end{equation}\r
+\r
+The three functions, \ref{eq:func_g}, \ref{eq:grad_g} and \ref{eq:hess_g}, are implemented in the Python code below.\r
+\r
+\lstinputlisting[language=Python]{bj_function.py}\r
+\r
+Consider the Hessian $\nabla^{2}g(\mathbf{x})$, and any vector $\mathbf{v} \in \mathbb{R}^{n}_{*}$.\r
+Then we have\r
+\r
+\begin{eqnarray}\r
+\mathbf{v}^{T}(\nabla^{2}g(\mathbf{x}))\mathbf{v} &=& \mathbf{v}^{T}(H+C(\mathbf{x}))\mathbf{v} \nonumber \\\r
+&=& \mathbf{v}^{T}H(\mathbf{x}))\mathbf{v}+\mathbf{v}^{T}C(\mathbf{x})\mathbf{v}.\r
+\end{eqnarray}\r
+We already know H is positive definite, so $\mathbf{v}^{T}H(\mathbf{x}))\mathbf{v} > 0$. \r
+Since $C(\mathbf{x})$ only has positive entries, we easily see that\r
+\r
+\begin{equation}\r
+\mathbf{v}^{T}C(\mathbf{x})\mathbf{v} = \sum\limits_{i=1}^n c_{i}(v_{i}x_{i})^2 \geq 0\r
+\end{equation}\r
+Hence $\mathbf{v}^{T}(H+C(\mathbf{x}))\mathbf{v} > 0$, and we see by definition that the Hessian, $\nabla^{2}g(\mathbf{x})$, is positive definite.\r
+\end{document}\r