how to store the intermediate result when using fmincon

Dear fellows, I am using fmincon to do optmization. Could you tell me how to look at and store the intermediate result when fmincon is trying different value? Well, I need to give an initial value for fmincon to start, and after that, it will try different value to find the optimized one. I want to check all those values that it tried and the corresponding results. Cheers

 採用された回答

Shashank Prasanna
Shashank Prasanna 2013 年 1 月 30 日

0 投票

You can use OutputFcn to access values at each iteration.
See the following link for more information:
In the optionset you can use the function as below:
options = optimset('OutputFcn',@outfun)

9 件のコメント

xueqi
xueqi 2013 年 1 月 30 日
Hi Thanks. A further question is, it seems fmincon keeps doing the iterations at the initial value, do you know what are the possible reasons?
Shashank Prasanna
Shashank Prasanna 2013 年 1 月 30 日
I will have to see the code and output to answer that. How is your objective surface? What does the display say about the values of gradient, First Order optimality constraints etc. Is there a code I can run to try it?
xueqi
xueqi 2013 年 2 月 5 日
Hi sorry about late reply. And also sorry that I am not quite understand your sugguestions. For objective surface I think it is flat in the top but still there will be a top value. It doesnt say anything about the values of gradient and first order optimality constraint. In what direction you suggest I should look into?
I would like to show you the code, but it is really a big one and include around 10 different files and may need loads of introducation...
xueqi
xueqi 2013 年 2 月 5 日
oh wait I think I can get the gradient
Shashank Prasanna
Shashank Prasanna 2013 年 2 月 5 日
I want to understand what you mean by "keeps doing the iterations at the initial value" Use the options
optimset('Display','iter')
and paste the output so that we can get an idea.
xueqi
xueqi 2013 年 2 月 5 日
I have dont that but the seems the program is keeps working and so I cant get the final input. Can I know you email then I can send you all the functions and dataset?
xueqi
xueqi 2013 年 2 月 5 日
Sorry it is final out not final input
Shashank Prasanna
Shashank Prasanna 2013 年 2 月 5 日
編集済み: Shashank Prasanna 2013 年 2 月 5 日
I am not sure I follow you. I don't want the final output.
Just run your optimization and and even if it is stuck at an iteration, can you please paste what is on the screen? If you post it in the forum there may be other who may be able to help you better. If you don't provide enough information, no one will be able to help you.
xueqi
xueqi 2013 年 2 月 5 日
It needs to read in data in excel file. I can I also put into excel file here? Thanks!

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

その他の回答 (3 件)

xueqi
xueqi 2013 年 2 月 5 日

0 投票

It needs to read in data in excel file. I can I also put into excel file here? Thanks!
Alan Weiss
Alan Weiss 2013 年 2 月 5 日

0 投票

Use the xlswrite function to export data to an Excel file.
Alan Weiss
MATLAB mathematical toolbox documentation
Daniel Frisch
Daniel Frisch 2020 年 10 月 7 日

0 投票

You can use my function outputFcn_global that saves all the intermediate results in a global variable, so you can inspect them later on.

カテゴリ

ヘルプ センター および File ExchangeData Import from MATLAB についてさらに検索

タグ

質問済み:

2013 年 1 月 30 日

回答済み:

2020 年 10 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by