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?

3 views (last 30 days)
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

Ameer Hamza
Ameer Hamza on 9 Aug 2018
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
Ameer Hamza
Ameer Hamza on 9 Aug 2018
.* 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.

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!