lsqnonlin - output value at each iteration?
6 views (last 30 days)
Show older comments
Using lsqnonlin, how do I output the value of each each iteration? It doesn't seem that the output arguments (x, resnorm, residual, exitflag, output, lambda, jacobian) contain this information.
Also, if I use opt = optimset('Display','iter-detailed'), I get the values: Iteration #, Func-count, Residual, First-Order Optimality, Lambda, and Norm of step. which don't actually tell me the value of each iteration.
1 Comment
Sonia
on 10 Jun 2015
I think you can simply add a "disp" command after definition of your objfun. Because what you pass to lsqnonlin is a vector, you can calculate your function value and eventually RMSE. Such as:
function objfun = objfun(prm)
(...define prm)
objfun = Tfield_obj-Tsim_obj;
lsqnonlin_value = sum(objfun.^2);
nData = size(Tfield_obj,1);
iter = iter+1
RMSE_iter(end+1) = sqrt(lsqnonlin_value/nData);
disp(['--- Current FunEval/Iteration completed. ObjFun value: ',num2str(lsqnonlin_value),'. RMSE: ',num2str(RMSE_iter(end)),' ---'])
end
I also wanted to know how the lsqnonlin is progressing in parameters update, so at each parameter update I requested it to output the current parameter combination (updated at each function evaluation/iteration):
function objfun = objfun(prm)
varParams(step).kfrost = prm(1); % kfrost
varParams(step).Porosity = prm(2); % Porosity
varParams(step).a = prm(3); % a
varParams(step).b = prm(4); % b
disp('----------- NEW PARAMETER GUESS -----------')
disp(['Running FunEval with new parameter guess: '...
'kfrost = ',num2str(varParams(step).kfrost),' [W/m/K], '...
'Porosity = ',num2str(varParams(step).Porosity),' [m3/m3], '...
'a = ',num2str(varParams(step).a),' [-], '...
'b = ',num2str(varParams(step).b),' [-].'])
(...define objfun)
end
What lsqnonlin displays during the iterative display are best result of all function evaluations within the given iteration.
Answers (1)
Steve Grikschat
on 25 Jul 2011
I'm not sure what you mean by "value of each iteration". The parameter values? The value of your system (F(x))?
Either way, look into OutputFcns, which lsqnonlin will call at each iteration. The information you're looking for is likely "x" or something in the optimValues structure.
See:
and
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!