How to output multiple results via function

1 回表示 (過去 30 日間)
Xin CUI
Xin CUI 2016 年 4 月 11 日
コメント済み: jgg 2016 年 4 月 11 日
Maybe this is a basic question. Please help me with it. I define a function with a couple parameters.
function f=fun(y,lambda)
[y,fval]=fmincon(@(y)fun(y,lambda),y0,[],[],[],[],[],[],[],[])
y is chosen to minimize function fun. The outputs are y and fval. I would like to output some other values, for example, y*lambda. I know I can output y*lambda in the next step after fmincon. How to output y*lambda directly in the function or in optimization problem?

採用された回答

jgg
jgg 2016 年 4 月 11 日
Do you mean from the function fun?
It's pretty easy:
function [f,yl,otherstuff] =fun(y,lambda)
[y,fval]=fmincon(@(y)fun(y,lambda),y0,[],[],[],[],[],[],[],[]);
yl = y*lambda;
otherstuff = otherstuff_create();
end
Like this.
  2 件のコメント
Xin CUI
Xin CUI 2016 年 4 月 11 日
Thanks for your prompt response. But it seems that when I ran it it still shows only y and fval, not y1 and otherstuff. Do you have any idea?
jgg
jgg 2016 年 4 月 11 日
You have to store the output as well, or display it. For instance, you would call that function like this:
[f,yl,otherstuff] = fun(y,lambda)
I'm not sure exactly what your function is, though, so I can't be more precise.

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

その他の回答 (0 件)

カテゴリ

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