How to solve "Check for incorrect argument data type or missing argument in call to function 'exp'" in matrix for linear program
20 ビュー (過去 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
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
2021 年 8 月 4 日
編集済み: 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 Center および File Exchange で Cash Flows についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!