Implement two methods: the gradient and the Gauss-Newton,
in a Matlab function with the interface specified below:
function [x,iter,nf,fh,gh] = mysolver(func,x0,tol,maxit,method,varargin)
%
% Solver for least squares problems min f(x) = 0.5*r(x)'*r(x)
%
% Output:
% x -- solution
% iter -- number of iterations taken
% nf -- number of func evaluations
% fh -- function values at all iterations
% gh -- gradient norms at all iterations
% Input:
% func -- function (handle) that returns [r, J] for given x
% x0 -- initial guess for x
% tol -- tolerance for gradient norm
% maxit -- maximum allowable iteration number
% method -- 1 for gradient, 2 for Gauss-Newton
Also implement a Matlab function
function [r,J] = myinvprJ(s,n,bvsE,cE,B)
% Output:
% r - residual at s
% J - Jacobian at s
% Input:
% s - parameters (3 x 1)
% n - number of interior nodes
% bvsE - boundary values used in experiments (2 x E)
% cE - observed data in experiments (|B| x E)
% B - indices for observation locations
to evaluate r and its Jacobian J
for the least squares problem where the unknowns are
s(j) for j = 1,2,3 -- the coefficients of the
polynomial function of x.
Your solver will call this function to solve the inverse problem.