-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmodeloutputs.m
49 lines (31 loc) · 1.25 KB
/
modeloutputs.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
%Benchmarck :
% Consider a multivariable fourth order system a,b,c,d
% with 3 inputs and 2 outputs:
clc;
u1 = u;
% The state space system equations:
% x_{k+1) = A x_k + B u_k
% y_k = C x_k + D u_k
% Model output:
ym = dlsim(A1,B1,C1,D1,u1)'; % MOESP output
yn = dlsim(A2,B2,C2,D2,u1)'; % N4SID output
%-------------Plot system outputs and model outputs-------------------------
figure (1)
hold off;subplot;clf;
subplot(211);plot(tt,y(1,:),'r',tt,ym(1,:),'*b');
title('First ouput');
legend('System output', 'MOESP output');
subplot(212);plot(tt,y(2,:),'r',tt,ym(2,:),'*b');
legend('System output', 'MOESP output');
title('Second output');
figure (2)
hold off;subplot;clf;
subplot(211);plot(tt,y(1,:),'r',tt,yn(1,:),'*b');
title('First ouput');
legend('System output', 'M4SID output');
subplot(212);plot(tt,y(2,:),'r',tt,yn(2,:),'*b');
legend('System output', 'N4SID output');
title('Second output');
%----------------Mean square error--------------------------------------------
errMOESP = (sum((y(1,:)-ym(1,:)).^2)+sum((y(2,:)-ym(2,:)).^2))/N
errN4SID = (sum((y(1,:)-yn(1,:)).^2)+sum((y(2,:)-yn(2,:)).^2))/N