%The script DIRECTID  implements the example of Sira-Ramirez and Colina-Morles
% from the Dec 1995 issue of the IEEE Transactions on CAS of direct-dynamics identification
% of the Kapitsa pendulum.
% The script uses the function file PLANT  for the plant model of Kapitsa pendulum.

clear;clf;
%x_0=[.1 0 0 1 .1 0 0 0 .1 0 0]'; 
x_0=[.1 0 0 -1 .1 0 0 0 .1 0 0]';
%[initial x; initial weight; initial plant states alpha, p and z]
 
tspan=[0 .25];
[t,x]=ode23s('plant',tspan,x_0);
for i=1:length(t)
   y_a(i)=x(i,1)*x(i,5)+x(i,2)*x(i,6)+x(i,3)*x(i,7)+x(i,4)*x(i,8);
   y_p(i)=x(i,9);
end
plot(t,y_a,'--',t,y_p)
set(gca,'Fontsize',12)
xlabel('Time (sec)','Fontsize',12)
ylabel('Plant and adaline outputs','Fontsize',12)
title('Forward dynamics identification---Section 9.2','Fontsize',12)
grid
legend('adaline output', 'plant output') 
