Problems starting with (554) will be required only from CAAM 554 students (similarly for those with (454)).
function [x,sflag,hist] = myBFGS(func,x0,tol,maxit) % % Quasi-Newton method using inverse BFGS update % (if you do backtracking, make sure you check y'*s > 0) % % Usage: % [x,sflag,hist] = myBFGS(func,x0,tol,maxit); % % INPUT: % func - matlab function for f and g evaluations % x0 - starting point (column vector) % tol - stopping tolerance for gradient norm % maxit - maximum number of iterations % % OUTPUT: % x - computed approximate solution % sflag - status flag, contains number of iterations % if convergence achieved or 0 if maxiter reached % hist(1,:) - vector of function values at all iterations % hist(2,:) - vector of gradient norms at all iterations--- Use the identity matrix for the initial inverse Hessian approximation.
[x,iter] = MyGN(func,x,tol,maxiter,prt,varargin);
where func is a function name that returns [r,J],
prt is a switch for printing iteration info or not,
and varargin is a variable list of input arguments
to be used by function func. The stopping criterion
should be norm(g) < tol, where g = J'*r is the
gradient vector.
Download and unzip the set of codes in nls.zip. Download the instructor's codes ZyGN.p and ZyLM.p (and pre-07 versions ZyGN07.p and ZyLM07.p). Study and run the test code testNLS.m. Without input, it runs the instructor's codes (CodeRange = 3:6) by default. We included 33 test problems, as described in the paper MGH.pdf. The test problems have already been coded. A program FdNewton.m is included that implements Newton's method for solving nonlinear systems using a finite-difference scheme to approximate Jacobian. You may start your programming by studying and modifying this program.
Submit your code and printout from the test program testNLS.m for the following two runs:
testNLS(1, 1.e-4,1:4); (easy run)
testNLS(10,1.e-8,1:4); (hard run)
function [x,iter,nf] = myGD(func,x0,tol,maxit,varargin)to minimize a function defined by the function handle func starting from initial guess x0. You interface func by
[f,g] = feval(func,x,varargin{:}); % function and gradient
f = feval(func,x,varargin{:}); % function value only
Use back-tracking line search and choose your own parameters.
The stopping criterion is either
crit := norm(g)/(1 + abs(f)) < tol;or the maximum iteration number maxit is reached. The outputs include an approximate solution, the iteration number taken, and the number of function evaluations taken. You should mimic the printout format as in the instructor's code.
Download the test scripts testDenoise.m and testDeblur.m, the functions TVL2N.m and TVL2B.m, and the instructor's code zGD.p (also for pre-2007 versions zGD07.p). You can run the test scripts without your codes in place.
Run the test scripts with your code (you will need image processing toolbox). Submit your code and printout including graphs, and a short report (typed) explaining what you observe in these experiments.
function [x,iter,nf] = myCGD(func,method,x0,tol,maxit,varargin)where method = 1,2,3,4 corresponding to GD, CG-PR, CG-PR+ and CG-FR, respectively. Check the search direction at each iteration. If a direction is not descent, use either the opposite direction or the steepest descent direction instead. Download the test scripts testDenoiseCGD.m, testDeblurCGD.m and the instructor's code zCGD.p. You should mimic the printout format as in the instructor's code.
Run the scripts with your code. Submit your code and the printout including graphs, and a short write-up (typed) explaining what you observe in these experiments.
function [x,iter,nf] = myNewton(func,x0,tol,maxit,varargin).Stop the iterations when the norm of the gradient is less than the tolerance. Test the solver on f(x) = (x'*A*x)^2/4 + (sum(x) - n)^2/20. You need to supply a Matlab function [f,g,H] = fhw8(x,A) to calculates the function, gradient and Hessian values for this function.
Change the stopping criterion in myCGD.m so that it stops when the relative change in function value becomes less than the tolerance. Call it myCGD2.m. Download the test script testNewton.m, and run it for n = 500, 1000. Submit a short write-up (typed) explaining your observations in these experiments, such as convergence rates, with printout and other necessary supporting evidence.
xk+1 = xk + (1 - ηk)pk, for some ηk in [0,η],where pk is the Newton direction at xk.
Download the test script testGM1p.m and the instructor's code zGMRES1p.p. You can run the script without your code. When your code is ready, run the test script for n = 500 or larger (but use smaller values in the testing phase). Submit a copy of your program, the printput (graph not necessary), and a short write-up (typed) explaining what you observe in this experiment.
Download the test scripts testGM2.m and testGM2a.m, and the instructor's code zGMRES2.p. You can run these scripts without your code. When your code is ready, run testGM2 for m = 100 or larger (as large as you see fit), and also run testGM2a. Submit a copy of your program, the printputs (graph included) from your runs, and a short write-up (typed) explaining what you observe in the experiment (testGM2a).
Download the test script testGM1.m, the function fdm4pde1.m for matrix generation, and the instructor's GMRES code zGMRES1.p. You can run the test script with or without your code. After you have written your code, start running the test script for a small m (say, m = 40) to debug and improve your code.
Submit your code and all printout for runs with m = 60, 80, or with m = 80, 100 (or even larger) if you can handle them comfortably.
Download the test script testsor.m and the
instructor's code zSOR.p. You can run
"testsor.m" with or without your code.
After you have debugged your code, run "testsor.m" with mode = 1
and N <= 100 (try smaller N first), and then run it
with mode = 2 and N >= 200 (or larger),
and with a good omega values that you can estimate.
Submit a copy of your program, the screen printout and the pictures
for the above 2 runs.
to implement the Jacobi and Gauss-Seidel methods, respectively, where maxit is the maximum number of iterations. Use the zero vector to start. The stopping criterion is that the residual 2-norm, norm(b-A*x), becomes less than tol*(1 + norm(b)). The output info is a character string indicating the status of termination: either "Converged at iteration ?" or "Maxit reached". And res is a vector containing residual norms, norm(b-A*x), for all iterations, counting iterations from 1.
Download the instructor's codes zJacobi.p, zGS.p and the test script test1.m. Read the test script.
Run test1.m for N = 80, 120, 160 (or larger if so desired), and with both method = 'Jacobi' and method = 'GS'. Submit your programs and output from these runs.