How to solve "Check for incorrect argument data type or missing argument in call to function 'exp'" in matrix for linear program

27 次查看(过去 30 天)
I'm trying to set up the matrices for my linear program to simulate the usage of distibuted energy resources in a microgrid.
When setting up the matrices I get the following error message (I also attached an example of the simulated price data):
Check for incorrect argument data type or missing argument in call to function 'exp'.
Error in (line 91)
f=[OMVar_L+(exp(Y(n,T))*Phi+FTDCharge)/EEff_L; (exp(X(n,T))+ETDCharge); (exp(Y(n,T))*Phi+FTDCharge)/HEff; 0;
EDRCost; HDRCost];
I don't understand why I'm getting this error which is why every help is much appreciated.
Code Extract:
% Test file
...
N = 365; % number of sample paths
T = 365; % number of decision-making steps
h = 24; % number of hours per day
Phi = 3.412; % conversion factor from MMBTU to MWh (MMBTU/MWh)
...
% length of time step in years
dt = 1/T;
% demand data
ED=zeros(T,1);
HD=zeros(T,1);
ED=readtable('ED.xls');
HD=readtable('HD.xls');
% periodic discount factor
Beta = exp(-r*dt);
% generate N correlated sample paths for X and Y
X = zeros(N,T);
Y = zeros(N,T);
X=readtable('Simulated Log Electricity Prices Test');
Y=readtable('Simulated Log Gas Prices Test');
for n=1:N
% define objective function coefficients
f=[OMVar_L+(exp(Y(n,T))*Phi+FTDCharge)/EEff_L; (exp(X(n,T))+ETDCharge); (exp(Y(n,T))*Phi+FTDCharge)/HEff; 0; EDRCost; HDRCost];
% define inequality constraint coefficients and rhs
A=[1 0 0 0 0 0
-HR_L 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1];
b=[G_L*h; 0; MaxEDR*ED(T); MaxHDR*HD(T)];
% define equality constraint coefficients and rhs
Aeq=[1 1 0 0 1 0
0 0 1 1 0 1];
beq=[ED(T); HD(T)];
% set lower-bound constraints on the decision variables
lb = zeros(6,1);
% solve the LP
[x fval] = linprog(f,A,b,Aeq,beq,lb);
Gen_L(n,T)=x(1);
EPurchase(n,T)=x(2);
NGHeat(n,T)=x(3);
DGHeat(n,T)=x(4);
EDResponse(n,T)=x(5);
HDResponse(n,T)=x(6);
V(n)=fval;
end
  2 个评论
Jakeb Chouinard
Jakeb Chouinard 2021-8-3
编辑:Jakeb Chouinard 2021-8-3
We will need to understand what the files look like that you're trying to read the table from. It is possible that your indexing for the table is referring to the wrong location or to something that is being stored as a char rather than a double, which would cause the exp function to fail.

请先登录,再进行评论。

采纳的回答

Eike Blechschmidt
编辑:Eike Blechschmidt 2021-8-4
The following returns a table.
X=readtable('Simulated Log Electricity Prices Test');
If you index it using the following a table is returned.
X(1,1)
The exp-function on the other hand is not defined for table input.
If you replace all
Y(n,T)
by
Y{n,T}
It should be working.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by