How to use fmincon with vectors? (error message: not enough input arguments)

1 回表示 (過去 30 日間)
Chang seok Ma
Chang seok Ma 2021 年 4 月 6 日
編集済み: Matt J 2021 年 4 月 6 日
Hello,
I am trying to use fmincon to find values that maximizes the function. (2 variables)
The document on the website provides sample that provides scalar and I want to return vectors instead of it.
Below is the sample code I wrote to understand how fmincon works.
test = [1 2 3 4];
fun = @(c,d)100*(c-d^2)^2 + (test(:)-c).^2;
fun(2,3)
lb = [0,0.2,0,0.2 ; 0,0.2,0,0.2];
ub = [0.5,0.8,0.5,0.8 ; 0.5,0.8,0.5,0.8];
A = [];
b = [];
Aeq = [];
beq = [];
x0 = [1/4,1/4,1/4,1/4 ; 1/4,1/4,1/4,1/4 ];
[x,val] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub)
So basically, I want to have (c,d) that maximizes fun for each value in test.
But when I run this code, it says 'Not enough input arguments'.
Seems like I made some mistake but couldn't find it.
Any help? Thanks in advance.

採用された回答

Matt J
Matt J 2021 年 4 月 6 日
編集済み: Matt J 2021 年 4 月 6 日
fun = @(x) -100*(x(1,:)-x(2,:).^2).^2 + (test-x(1,:)).^2;
  8 件のコメント
Chang seok Ma
Chang seok Ma 2021 年 4 月 6 日
So if the problem is not additively separable, is there other way I could solve this problem without loop?
Matt J
Matt J 2021 年 4 月 6 日
編集済み: Matt J 2021 年 4 月 6 日
If the problem weren't separable, using a loop would not be an option. You would be forced to solve it as an 8D minimization problem.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by