---
# System prepended metadata

title: Discussion Board for 02610 Exercises

---

# Discussion Board for 02610 Exercises

At here, you can post your questions, and can also answer the questions posted by the others. 
- You can write mathematical expressions as in Latex, e.g. $\lambda=1$. 
- You can insert your code in your question in Matlab (or other programming language) format. You can do like this:
``` matlab=
function f = myfun(x)
if x > 1
    x = x + 1;
end 
```
- You also can include images, tables, etc..

*Now let's try it out.* :smile: 

## Q & A:
1. Question 1: 

Regarding the implementation of the Newton's method in 2.3 (2).

I implemented it like this:
But it seems to never converge no matter which parameter values i use (exceeding the maximum number of allowed iterations). 
``` matlab=
function [x,stat] = newton(alpha,fundfun,x0,varargin)
% Solver settings and info
maxit = 100*length(x0);
tol = 1.0e-10;
stat.converged = false; % converged
stat.nfun = 0; % number of function calls
stat.iter = 0; % number of iterations
% Initial iteration
x = x0;
it = 0;
[f,df,d2f] = feval(fundfun,x,varargin{:});
converged = (norm(df,'inf') <= tol);
stat.nfun = 1;
% Store data for plotting
stat.X = x;
stat.F = f;
stat.dF = df;
stat.d2F = d2f;
% Main loop of Newton's method
while ~converged && (it < maxit)
it = it+1;
% Newton's step
% TODO -- Insert code between the lines
% ================================================
pk = -(d2f)^(-1)*df;
x = x + alpha*pk
% ================================================
[f,df,d2f] = feval(fundfun,x,varargin{:});
converged = (norm(df,'inf') <= tol);
stat.nfun = stat.nfun+1;
% Store data for plotting
stat.X = [stat.X x];
stat.F = [stat.F f];
stat.dF = [stat.dF df];
stat.d2F = [stat.d2F d2f];
end
% Prepare return data
if ~converged
x = [];
end
stat.converged = converged;
stat.iter = it;
end
```

Answers: Try to use backslach in Matlab to solve $-\nabla^2 f(x_k)^{-1} \nabla f(x_k)$, i.e. 
```-d2f\df.```