Minimize second output of a function with respect to a variable.
3 ビュー (過去 30 日間)
古いコメントを表示
Say I have an function of several variables with vector output, say, [a,b]=myfun(x,y,z);
Now, say I want to create a function that passes the parameters y and z and minimizes myfun with respect to x, so that the first output is minimized. So I could do something such as this:
function c = myfun2(x,y)
x0=1;
c = fminunc(@(x)myfun(x,y,x),x0)
end
But what if want to create a function, say fun3, that passes x and y as in fun2 but so that the second output of myfun is minimized. How could I do that without redefining myfun (or creating a new function) in an m file?
0 件のコメント
回答 (1 件)
Neha Talnikar
2014 年 7 月 22 日
“fminunc” expects the objective function to return a scalar.
To minimize the objective function with respect to the second output of the function “myfun”, you could write another function which calls the “myfun” and returns the second output only.
function out = secondArgument(x,y,z)
[~,out] = myfun(x,y,z);
end
This function could then be used for minimizing as follows:
function c = myfun2(y,z)
x0=1;
c = fminunc(@(x) secondArgument(x,y,z),x0)
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Surrogate Optimization についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!