LINPROG requires the following inputs to be of data type double: 'f'.

3 views (last 30 days)
%% Discrete modelling
Ae=(1-(K*ts)/Cth);
B=(ts*COP*HP)/Cth;
D=ts*K/Cth;
u=zeros(1,i);
Tin=zeros(1,i);
x=zeros(3,i);
cost=[gamma;zeros(1,1008);zeros(1,1008)];
xcost=zeros(3,i);
for j=1:i
if j>1
Tin(j)=Ae*Tin(j-1)+B*u(j-1)+C*Tout(j-1);
x=[u(j-1);Tin(j-1);gamma(j-1)];
else
Tin(j)=0;
u(j)=0;
x(j)=0;
end
% x=[u(j);Tin(j);gamma(j)];
cost=[gamma(j);0;0];
f=@(x) sum(cost(j).'*x(j));
%Starting point%
x0=0;
%Constraints%
%Inequality const%
A=[1 0 0;-1 0 0;0 1 0;0 -1 0;0 0 1;0 0 -1];
b=[umin; -umax; Tmin; -Tmax; gammamin; -gammamax];
options = optimoptions(@linprog,'Display', 'off');
[x(j),xcost(j)]=linprog(f,x0,A,b);
end

Answers (1)

Ameer Hamza
Ameer Hamza on 18 Oct 2020
Edited: Ameer Hamza on 18 Oct 2020
linprog() does not require you to multiply 'f' with x. It will do that internally. Just directly give the vector 'f'
f = cost; % instead of f = @(x) sum(cost(j).'*x(j));
  2 Comments
Ricardo López
Ricardo López on 18 Oct 2020
I am still getting this error: The number of rows in A must be the same as the number of elements of b.
And I also tried to solve this by fmincon with f = @(x) sum(cost(j).'*x(j));
Ameer Hamza
Ameer Hamza on 18 Oct 2020
The dimensions of A and b seem to be fine? Can you add a breakpoint and see if the dimensions are correct when the issue happens?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!