Why do I get Index exceeds the number of array elements (1).

2 ビュー (過去 30 日間)
Maxim Baurov
Maxim Baurov 2020 年 7 月 1 日
回答済み: bharath pro 2020 年 7 月 2 日
Hello, this is my function
fun = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
x0 = 0.5;
A = [1;2];
b = [1;2];
[x,fval] = fmincon(fun,x0,A,b,[],[],[],[],[]);
when I try to run it I get an error, but i dont understand why

回答 (1 件)

bharath pro
bharath pro 2020 年 7 月 2 日
The error is caused because x0 is scaler but the function fun needs a vector ( x(1) and x(2) ). The following code works fine after I changed the dimensions of X0, A and B.
fun = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
x0 = [0.5,0.6];
A = [1,2];
b = 1;
[x,fval] = fmincon(fun,x0,A,b,[],[],[],[],[]);

カテゴリ

Help Center および File ExchangeNonlinear Optimization についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by