How do I minimise function with many outputs?

조회 수: 11 (최근 30일)
Vykta Wakandigara
Vykta Wakandigara 2018년 11월 2일
댓글: Walter Roberson 2018년 11월 2일
I have an anonymous function which produces multiple outputs. How do I use fmincon to minimise with respect to the first output?

채택된 답변

Walter Roberson
Walter Roberson 2018년 11월 2일
Where you currently have
fmincon(HandleToAnonymousFunction, ......)
use
fmincon(@(X) HandleToAnonymousFunction(X), .....)
This will have the effect of discarding all except the first output.
I am assuming here that when you say that it produces multiple outputs, that you mean that the current function does something like deal() to emit multiple output variables, or else is a simple handle to a function that has multiple potential outputs such as min: @min would be an example of an anonymous function that can return multiple outputs.
If what you mean is instead that your function returns a vector or array of values instead of a scalar, then the approach would be
First = @(V) V(1);
fmincon(@(X) First(HandleToAnonymousFunction(X)), .....)

추가 답변 (1개)

Caglar
Caglar 2018년 11월 2일
편집: Walter Roberson 2018년 11월 2일
  댓글 수: 1
Walter Roberson
Walter Roberson 2018년 11월 2일
That material is still correct, but deals primarily with the case that the output to be returned is not the first output. The first output can be handled differently.

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by