Minimization with discrete variable
7 次查看(过去 30 天)
显示 更早的评论
I have some discrete variables of motor torque and speed. Ex: motor 1 has 6 Nm torque and 42 rpm, motor 2 has 9 Nm torque and 62 rpm, etc. I have to find the correct motor specification when applied on some mechanism and load and I already had the linearized function of this mechanism. I have to use optimization tool on Matlab. How can I put the discrete variable into matlab and how can I do the optimization? Really need help.
3 个评论
jgg
2016-1-12
I assume the secondary issue is that you have a very very large number of these so that enumeration is not feasible?
采纳的回答
Torsten
2016-1-13
xvec=[12.7 15.875 19.05 25.4 31.75 38.1 50.8 63.5];
yvec=[1.27 1.5875 2.54 3.175];
zvec=[0.05 0.1 0.15 0.2];
obj =[7.44 4.19 1.70 2.25 3.80 1.42 1.69 0.43 0.53 1.26 0.97 0.68 0.72 0.58 0.42 0.35];
fun=@(x,y,z) 3*x/2*(y+3.14*z*x)/(3.14*x-x*y);
minimum = Inf;
k1_ref = 0;
k2_ref = 0;
k3_ref = 0;
for k1 = 1:length(xvec)
x=xvec(k1)
for k2 = 1:length(yvec)
y=yvec(k2)
for k3 = 1:length(zvec)
z=zvec(k3)
result = fun(x,y,z);
if result < minimum & any(abs(obj-result)<1e-6)
minimum = result;
k1_ref = k1;
k2_ref = k2;
k3_ref = k3;
end
end
end
end
xvec(k1_ref),yvec(k2_ref) and zvec(k3_ref) should be combined to give the minimum value contained in the array "obj".
If no combination exists for which the value is contained in "obj", k1_ref, k2_ref and k3_ref will keep their starting values, namely 0.
Best wishes
Torsten.
4 个评论
Torsten
2016-1-13
xvec=[12.7 15.875 19.05 25.4 31.75 38.1 50.8 63.5];
yvec=[1.27 1.5875 2.54 3.175];
zvec=[0.05 0.1 0.15 0.2];
obj =[7.44 4.19 1.70 2.25 3.80 1.42 1.69 0.43 0.53 1.26 0.97 0.68 0.72 0.58 0.42 0.35];
fun=@(x,y,z) 3*x/2*(y+3.14*z*x)/(3.14*x-x*y);
minimum = Inf;
k1_ref = 0;
k2_ref = 0;
k3_ref = 0;
for k1 = 1:length(xvec)
x=xvec(k1)
for k2 = 1:length(yvec)
y=yvec(k2)
for k3 = 1:length(zvec)
z=zvec(k3)
result = fun(x,y,z);
if result < minimum
minimum = result;
k1_ref = k1;
k2_ref = k2;
k3_ref = k3;
end
end
end
end
value_from_obj = min(obj(obj-fun(xvec(k1_ref),yvec(k2_ref),zvec(k3_ref))>=0));
Best wishes
Torsten.
更多回答(2 个)
Alan Weiss
2016-1-12
If you can specify your problem as a mixed-integer linear programming problem, use the intlinprog function. There are several examples on that page that can help you with problem formulation.
If it is impossible to put into the MILP framework, use the ga solver from Global Optimization Toolbox to solve your mixed integer optimization. You might find some help in this example.
Alan Weiss
MATLAB mathematical toolbox documentation
0 个评论
jgg
2016-1-12
编辑:jgg
2016-1-12
It's a little bit unclear what your objective function is, but suppose it's something like f(A,B) where A and B are your discrete random variables. Provided that you have only a few levels of the random variables, you could make a nice program like this where:
A = [1,2,3,4]; B = [1,2,3,4];
Then, set something like:
a_val = @(x)(1*x(1)+2*x(2)+3*x(3)+4*x(4));
b_val = @(x)(1*x(1)+2*x(2)+3*x(3)+4*x(4));
Then, your objective function is f(a_val(x),b_val(y)) and you have the restriction your lower bound is zero and upper bound is one, and x and y sum to 1. You could then easily use ga to solve this by following the documentation.
An alternative if you have many levels is to make the variable the level:
f(A(la),B(lb))
where la and lb are the levels, and you restrict them to be between 1 and k where k is the number of levels. I think ga would work well here as well.
It's a little hard to give you more direct advice without more information.
6 个评论
Torsten
2016-1-13
This should be done in MATLAB, too.
It avoids that you have to calculate 128 values with a table calculator.
Best wishes
Torsten.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!