Error using lsim in Fitness function
3 次查看(过去 30 天)
显示 更早的评论
Dear community! I've realized a fitness function and actually I' m trying to run my fitness function in the command window with given defined inputs / parameters. But I always get this error:
Error using DynamicSystem/lsim (line 84) When simulating the response to a specific input signal, the input data U must be a matrix of numeric values with at least two rows (samples) and without any NaN or Inf.
Error in myFitness02 (line 40) [y,t_out,x] = lsim(sys_ss, data.InputData, t, x0);
par, y_ref and u_ref I have defined in the command window as follows: par= [1 64 364 22 22 30 108 9] y_ref = 22 u_ref = [5 200 3000]
I've also tried different types for y_ref as 1x3 Matrix, u_ref as 3x1 or 2x3). But without any effort. What do I am doing wrong? Could anybody please give me a hint? Thank you very much in advance!
if true
function mse = myFitness02(par,y_ref,u_ref)
R_re=par(1);
R_h=par(2);
R_ea=par(3);
A_w=par(4);
A_e=par(5);
C_r=par(6);
C_h=par(7);
C_e=par(8);
x0=[40,20,0];
t=1:length(y_ref);
% Dynamikmatrix / Zustandsmatrix A von Modell 2
A = [(-R_re-R_h)/(C_r*R_h*R_re), 1/(R_re*C_r) , 1/(R_h*C_r); ...
1/(R_re*C_r), (-R_ea-R_re)/(C_e*R_re*R_ea) , 0 ; ...
1/(R_h*C_h), 0 , -1/(R_h*C_h)];
% Eingangsmatrix B von Modell 2
B = [0, A_w/C_r, 0 ; 1/(R_ea*C_e), A_e/C_e, 0; 0, 0, 1/C_h ];
% Ausgangsmatrix C
C = [1,0,0];
% Durchgangsmatrix D
D = zeros(1,3);
Ts=0; %Sampling time, 0 indicates a continuous-time model
sys_ss=ss(A,B,C,D,Ts); % State Space Modell
data = iddata(y_ref,u_ref,10);
data.TimeUnit='seconds';
% data.InputName = {'Außentemperatur T_a', 'solare Einstrahlung q_rad_sol', 'Heizleistung Waermepumpe q_h'};
% data.InputUnit = {'°C'; 'W'; 'W'};
% data.OutputName = 'Raumtemperatur T_r';
% data.OutputUnit = '°C';
%data.InputData = zeros(length(y_ref),length(t))
[y,t_out,x] = lsim(sys_ss, data.InputData, t, x0);
mse = sum((y-y_ref).^2) / length(y)
end
end
0 个评论
回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!