% This script simulates the feedback system usign fuzzy models
%Plant=txt2fis('Plant.txt');
%Controller=txt2fis('Controller.txt');
Plant=readfis('Plant.fis');
Controller=readfis('Controller.fis');
tf=3.5;
X0=[10,10];
[t,x]=ode45(@fuzeval,[0,tf],X0,[],Plant,Controller);
figure,subplot(211),plot(t,x(:,1)),xlabel('Time (s)'),ylabel('X1'),title('X1'),grid
subplot(212),plot(t,x(:,2)),xlabel('Time (s)'),ylabel('X2'),title('X2'),grid
% Control Signals
U=zeros(2,size(x,1));
for i=1:size(x,1)
U(:,i)=fuzeval(x(i,:)',Controller);
end
figure,plot(t,U(1,:),t,U(2,:)),grid
title('Control Signals')
legend('U1','U2')
xlabel('Time (s)'),ylabel('U')