optimization in specifc range of boundary variable
2 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!