From: Bjørn Rustad Date: Fri, 30 Sep 2011 13:19:55 +0000 (+0200) Subject: Fix error in gradient X-Git-Url: http://git.rustad.me/?a=commitdiff_plain;h=0753a38cadae33e3b1f1a624a65d4705cf993c47;p=nummat1 Fix error in gradient --- diff --git a/function.py b/function.py index 480ceb9..5c9cd9f 100644 --- a/function.py +++ b/function.py @@ -13,7 +13,7 @@ def _C(x, c): # Calculate gradient of g in point x def gradient_g(x, H, b, c): - return -b.T + 0.5 * H.dot(x) + 0.5 * H.T.dot(x) + (1.0/3.0) * x.T.dot(_C(x,c)) + return -b + H.dot(x) + (1.0/3.0) * _C(x,c).dot(x) # Calculate hessian of g in point x def hessian_g(x, H, b, c): diff --git a/rapport.tex b/rapport.tex index 29a90b1..9befc0b 100644 --- a/rapport.tex +++ b/rapport.tex @@ -88,18 +88,13 @@ The function analyzed in this project was \label{eq:func_g} 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} \end{equation} - From equation \ref{eq:func_g} we get - -\begin{equation} +\begin{eqnarray} \label{eq:grad_g} -\nabla g(\mathbf{x}) = -\mathbf{b}^{T}+H\mathbf{x}+\frac{1}{3}\mathbf{x}^{T}C(\mathbf{x}), -\end{equation} -\begin{equation} +\nabla g(\mathbf{x}) &=& -\mathbf{b}+H\mathbf{x}+\frac{1}{3}C(\mathbf{x})\mathbf{x} \\ \label{eq:hess_g} -\nabla^{2}g(\mathbf{x}) = H+C(\mathbf{x}). -\end{equation} - +\nabla^{2}g(\mathbf{x}) &=& H+C(\mathbf{x}). +\end{eqnarray} The three functions, \ref{eq:func_g}, \ref{eq:grad_g} and \ref{eq:hess_g}, are implemented in the Python code below. \lstinputlisting[language=Python]{bj_function.py}