Write a Matlab function as 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 gradieng, 2 for Gauss-Newton
And implement a function to compute [r, J] for the inverse problem
where the 2 unknown parameters are the constant and the slope (in that order
for s_1 and s_2) of a linear function.