optimization in specifc range of boundary variable

2 ビュー (過去 30 日間)
mohammed hussein
mohammed hussein 2017 年 2 月 13 日
編集済み: mohammed hussein 2017 年 2 月 14 日
Hi
i need some help in my problem . i am working with optimization function (fmincon). i have specific number of boundary value , i do not have range
for example , the range of first variable in this example is form 0 to 1 but in my problem i have [0 1 1.2 1.5 1.7 1.9 2 2.3 ] . also in second variable for this example has from 0 to 2 but in my problem i have [0 1 1.8 1.9 1.99 2 2.5 2.9 ] . how can i do that ?
thank you
fun = @(x)1+x(1)/(1+x(2)) - 3*x(1)*x(2) + x(2)*(1+x(1));
lb = [0,0];
ub = [1,2];
A = [];
b = [];
Aeq = [];
beq = [];
x0 = [0.5,1];
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub)

採用された回答

Walter Roberson
Walter Roberson 2017 年 2 月 13 日
fmincon cannot be used for discrete variables.
fun = @(x1, x2) 1 + x1 ./ (1+x2) - 3 * x1 .* x2 + x2 .* (1 + x1);
x1_vals = [0 1 1.2 1.5 1.7 1.9 2 2.3 ];
x2_vals = [0 1 1.8 1.9 1.99 2 2.5 2.9 ];
[X1, X2] = ndgrid(x1_vals, x2_vals);
Z = fun(X1, X2);
[best_Z, idx] = min(Z(:));
x = [X1(idx), X2(idx)];
Now x is the location of the best combination.
  1 件のコメント
mohammed hussein
mohammed hussein 2017 年 2 月 14 日
編集済み: mohammed hussein 2017 年 2 月 14 日
thank you very much for your answer .

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by