48 views (last 30 days)

Show older comments

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

Jakeb Chouinard
on 3 Aug 2021

Eike Blechschmidt
on 4 Aug 2021

Edited: Eike Blechschmidt
on 4 Aug 2021

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.

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

Start Hunting!