Here in my code I defined A vector and B vector for my linear programing, the relationship between them is Ax=<B which A is a inequlity vector and B is a RHS and x is variable. the Error is in photo which i attached .how can I solve it?

this is the way I defined b_ineaualty_sec5 :
[b_ineq_sec5]=load_kw* ones(N_time_slots,1);
and this is the way I defined A_inequality_sec5 :
temp2=eye(N_time_slots);
[A_ineq_sec5]=generate_Cplx_Constraint_format( Vars_size, [3;9],-temp2,temp2);
the relationship between A and b is Ax=<b which A is a inequlity vector and B is a RHS and x is variable. I know the problem is with the size of b and A , but how should I define b ?
and this is vars_size and generate_cplex_format functions:
function [Vars_size]= create_variable_bundle(N_time_slots)
Vars_size=[1;N_time_slots;N_time_slots; N_time_slots; N_time_slots; N_time_slots; N_time_slots;N_time_slots;N_time_slots;N_time_slots;N_time_slots;N_time_slots ];
end
function [A_block]=generate_Cplx_Constraint_format( Vars_size, Var_select,varargin)
total_size=sum(Vars_size);
temp1= tril(ones(numel(Vars_size),numel(Vars_size)))*Vars_size;
temp1(numel(Vars_size))=[];
Start_ind= [0;temp1]+1;
temp2=size( varargin{1} ,1);
A_block=zeros(temp2,total_size);
% A x+ By < b
for i=1: numel(Var_select),
A_block(:,Start_ind(Var_select(i)): Start_ind(Var_select(i))+ Vars_size(Var_select(i))-1 )=varargin{i};
end
end

 Accepted Answer

This problem is happening because load_kw is probably not a scalar, wheres your code seems to indicate it is a scaler. If It is a vector, you need to take care of the dimensions of the two matrices for multiplication.

9 Comments

actually this is the way I defined load_value:
function [load_time_stamp, load_value]=get_the_actual_demand_data()
filename = 'dee1.csv';
delimiter = ',';
startRow = 2;
formatSpec = '%{MM-dd-yy HH:mm}D%*s%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'HeaderLines' ,startRow-2);
delimiter, 'TextType', 'string', 'EmptyValue', NaN, 'HeaderLines' ,startRow-1, 'ReturnOnError', false, 'EndOfLine', '\r\n');
a = datestr(dataArray{1,1},'yyyy-mm-dd HH:MM');
load_time_stamp = cellstr(a);
fclose(fileID);
formatSpec = '%*s%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'HeaderLines' ,startRow-2);
delimiter, 'TextType', 'string', 'EmptyValue', NaN, 'HeaderLines' ,startRow-1, 'ReturnOnError', false, 'EndOfLine', '\r\n');
load_value = dataArray{:, 1};
fclose(fileID);
end
end
But what is the value of load_kw when you run the code? The function in your comment does not tell what values are loaded in that variable.
it's Scalar . for each repeat in the simulation load_value has one value .
Can you give the code where the value of load_kw is calculated and modified? It appears that initially, it might be a scalar but in next iterations, it becomes a vector. Alternatively, try changing the line as follow
[b_ineq_sec5]=load_kw .* ones(N_time_slots,1);
The line
N_time_slots=size(load_kw,1);
seems to indicate that load_kw is not a scalar. It is a vector. Put a breakpoint on the following line
[b_ineq_sec5]=load_kw* ones(N_time_slots,1);
and check the value of load_kw right before execution of this line because the error message indicates that the value of load_kw is somehow not consistent for multiplication.
yes you were right. it's not scalar .and your alternative soulotion also worked and there is no sign of that error anymore. could you plz explain it ? and also i have a new error at the end of my code , new error is :
how can i solve it? it's again related to the m file that i sent before
.* is element-wise multiplication whereas * is matrix multiplication. The second operator requires the matrix dimensions to be consistent.
While for your 2nd error, It seems that you might be accidentally mixing ',' and ';'. , add elements to same row while ; creates a new row. You can add a breakpoint at that line to diagnose the error.
thank you for the feedback. your information was so useful to me. regards

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!