我想编写一个代码来找到运行洗碗机的最低成本。这取决于所需的功率、小时费率和使用的时间。我正在fmincon
为此使用,但是下面提供的代码显示以下错误消息:
用户提供的目标函数必须返回一个标量值
我的目标函数是最小化(总成本*时间)st总成本等于(小时功率)*(小时成本)从1小时到24小时的总和等于0.8千瓦时,而且总成本必须大于Ca
一天的总运行时间是一小时。
% Array showing the hourly electricity rates (cents per kwh)
R=zeros(24,1);
R(1:7,1)=6;
R(20:24,1)=6;
R(8:11,1)=9;
R(18:19,1)=9;
R(12:17,1)=13;
p_7 = transpose([0.8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]); %This is the power pattern of appliance (operates at 0.8 kWh for 1 hour daily)
for k=1:23
P7(:, k+1) = circshift(p_7,k); % This shows all the possible hours of operation
end
Total = P7*R; % This is the total cost per hour at different hourly tariffs
fun = @(x)Total.*(x);
x0 = [1];
A = Total;
%Ca = 0.5;
Ca = ones(1,24);
b = Ca;
Aeq = Total;
Daily_tot_7 = 2*ones(1,24);
beq = Daily_tot_7;
ub = 24;
lb = 1;
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub)
我相信我对将约束转换为的理解fmincon
是不正确的,并且我可能错过了这个问题的重要约束。