Please, I have limited time for a project. I'll like to know what this code does
显示 更早的评论
variables = {'as','aw','ah'};
N = length(variables);
%create variables for indexing
for v = 1:N
eval([variables{v},' = ', num2str(v),';']);
end
%Defining the lower bounds
lb = zeros(size(variables));
lb([as,aw,ah]) = [0,0,0];
%Defining the upper bounds
ub = Inf(size(variables));
ub([as,aw,ah]) = [Ns,Nw,Nh];
%Entrying linear inequality constraints
A = zeros(2,3);
A(1,[as,aw,ah]) = [-Ps(i),-Pw(i),-Ph(i)];
b(1) = -P_load(i);
A(2,[as,aw,ah]) = [Ps(i),Pw(i),Ph(i)];
b(2) = P_max;
%Linear Equality Constraints
Aeq=[];
beq=[];
%Objective Function
f = zeros(size(variables));
f([as aw ah]) = [Cus*Ps(i)*T Cuw*Pw(i)*T Cuh*Ph(i)*T];
%Solving the problem with linprog
[x fval] = linprog(f,A,b,Aeq,beq,lb,ub);
for d = 1:N
fprintf('%12.2f \t%s\n',x(d),variables{d});
end;
aso(i)=x(1), awo(i)=x(2), aho(i)=x(3);
P_Supply(i)=aso(i)*Ps(i)+awo(i)*Pw(i)+aho(i)*Ph(i);
cost(i)=fval/P_Supply(i);
2 个评论
John D'Errico
2015-6-7
编辑:John D'Errico
2015-6-7
http://www.mathworks.com/matlabcentral/answers/29922-why-your-question-is-not-urgent-or-an-emergency
If you have limited time, then perhaps you should have started sooner. Regardless, it is difficult to know what some random piece of lightly commented code does, given no real information. It is an optimization, but if you need to know more, then talk to the person you got it from.
Jan
2015-6-7
@Nganyu Derick: Of course you have a limited time for your project. This is the nature of projects. If you want to get a useful answer soon, care for a meaningful question. Your question is very general and it is not clear if you need an explanation of the "=" operator or of the command length(). You've posted code, which does not run due to several errors. Therefore we do not have teh faintest chance to guess reliably, what it should do. In consequence posting this question consumes the time of you and the readers without the possibility to obtain a useful answer.
采纳的回答
更多回答(2 个)
Ayush
2015-6-7
编辑:John D'Errico
2015-6-7
0 个投票
@Nganyu Derick
ERROR: Undefined function or variable 'Ns'.
PLease re-check your code
2 个评论
John D'Errico
2015-6-7
编辑:John D'Errico
2015-6-7
So? I gave an answer, as much as it deserved. I told them to ask the source. Perhaps you should give them a complete dissertation on what this code does, since you were so willing to volunteer my time.
Nganyu Derick
2015-6-7
编辑:Walter Roberson
2015-6-7
Walter Roberson
2015-6-7
0 个投票
It appears to me that it does some kind of load-flow optimization for an electrical system with three suppliers.
I think I must be missing some of what it is doing, as it looks to me as if the problem should be mechanically solvable without using linprog by using the least expensive source first up to its maximum capacity, the next most expensive source next, and so on, until the load has been met. My mind is a bit cloudy at the moment so I do not have confidence in that analysis.
3 个评论
Nganyu Derick
2015-6-7
Walter Roberson
2015-6-7
The first set of lines is a fancy way of making the assignment
as = 1; aw = 2; ah = 3;
lb is then set to a 1 x 3 vector of 0s, and then those locations in lb are overwritten by 0 (a useless step).
ub is set to a 1 x 3 vector of infinities, and then those values are overwritten by [Ns, Nw, Nh], leading to the same result as if you had just done ub = [Ns, Nw, Nh]
The code you quote here could be replaced with
lb = zeros(1,3);
ub = [Ns, Nw, Nh];
Nganyu Derick
2015-6-8
类别
在 帮助中心 和 File Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!