MATLAB: How to output Jacobian with lsqnonlin

jacobianlsqnonlinMATLABmultistart

Dear All,
I am interested in obtaining the variance-covariance matrix for my parameters – x (15 by 1) – which are the solution to the following nonlinear least squares minimization problem. I am using lsqnonlin.
My data consist of 18026 rows and 15 columns:
X = [X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,X13,X14];
y = eret2;
I need to estimate 15 parameters.
My function is:
function F = myfun(x,y,X)
F = (y - (1 + x(1)*(x(2)/0.0025662))*X(:,1) - (x(2)/x(3))*(sqrt(1-x(1)^2))*X(:,2) - x(4)*X(:,3) - x(5)*X(:,4)) - x(6)*X(:,5) - x(7)*X(:,6) - x(8)*X(:,7) - x(9)*X(:,8) - x(10)*X(:,9) - x(11)*X(:,10) - x(12)*X(:,11) - x(13)*X(:,12) - x(14)*X(:,13) - x(15)*X(:,14);
end
Constraints are:
lb = [-1,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1];
ub = [1,0.6,0.01,1,1,1,1,1,1,1,1,1,1,1,1];
Starting values are:
x0 = [0.2, 0.6, 0.10, 0.86,-0.05,-0.026,0.031,-0.017,0.002,-0.002,-0.003,0.003,0.025,0.013,-0.009];
I use the following statements where I submit 756 user defined starting values (sv = 756 by 15)
problem = createOptimProblem('lsqnonlin','objective',@(x) myfun(x, y, X),'x0',x0,'lb',lb,'ub',ub);
tpoints = CustomStartPointSet(sv);
[x,f] = run(ms, problem,tpoints);
I am able to obtain parameter estimates! Thanks to all the previous help on this group.
But now need to obtain the variance-covariance matrix for the parameters (15 by 15).
I would like to estimate my covariance matrix using the Jacobian.
I found the following code for the same:
Jacobian = full(Jacobian); %lsqnonlin returns the Jacobian as a sparse matrix
varp = resnorm*inv(Jacobian'*Jacobian)/N
stdp = sqrt(diag(varp)); %standard deviation is square root of variance
stdp = 100*stdp'./p; %[%]
My question is the following:
When I run:
problem = createOptimProblem('lsqnonlin','objective',@(x) myfun(x, y, X),'x0',x0,'lb',lb,'ub',ub);
[x,f,resnorm,residual,exitflag,output,lambda,J] = run(ms, problem,tpoints);
I get:
Error using MultiStart/run
Too many output arguments.
Could someone help me to solve this and output the Jacobian?
best, Srinivasan

Best Answer

The MultiStart run() function only has up to 5 outputs according to the documentation (<- link). Your code is asking for 8 outputs which is why you're getting that error.
To get the Jacobian, why not run lsqnonlin() directly since lsqnonlin() returns the jacobian?