lsqnonlin - output value at each iteration?

13 ビュー (過去 30 日間)
TSPQ
TSPQ 2011 年 7 月 21 日
コメント済み: Sonia 2015 年 6 月 10 日
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 件のコメント
Sonia
Sonia 2015 年 6 月 10 日
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.

サインインしてコメントする。

回答 (1 件)

Steve Grikschat
Steve Grikschat 2011 年 7 月 25 日
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

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by