필터 지우기
필터 지우기

Minimize second output of a function with respect to a variable.

조회 수: 3 (최근 30일)
Peter Laslo
Peter Laslo 2014년 7월 21일
답변: Neha Talnikar 2014년 7월 22일
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?

답변 (1개)

Neha Talnikar
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

카테고리

Help CenterFile Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by