Function: From multiple variables as input to vector input

조회 수: 2 (최근 30일)
Nicolas Ochmann
Nicolas Ochmann 2017년 8월 8일
댓글: Nicolas Ochmann 2017년 8월 8일
Hi everybody,
I have the following problem: I have a function such as: fun = @(x1,x2)100*(x2-x1^2)^2+(1-x1)^2
However, I need to convert this to the form: fun = @(x)100*(x(2)-x(1)^2)^2+(1-x(1))^2 so that I can use it as the objective function for fmincon.
Does anybody have a clue how this can be done?
Thanks in advance,
Nicolas

채택된 답변

Stephen23
Stephen23 2017년 8월 8일
편집: Stephen23 2017년 8월 8일
Either rewrite the function exactly as you have shown, or put it inside a wrapper:
foo = @(x)fun(x(1),x(2));
Note the different function name.

추가 답변 (0개)

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by