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

조회 수: 3 (최근 30일)
Ricardo López
Ricardo López 2020년 10월 18일
댓글: Ameer Hamza 2020년 10월 18일
%% 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

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 10월 18일
편집: Ameer Hamza 2020년 10월 18일
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
Ricardo López
Ricardo López 2020년 10월 18일
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 2020년 10월 18일
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?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by