%The script IDI_SCR implements the example of Sira-Ramirez and Colina-Morles
% from the Dec 1995 issue of the IEEE Transactions on CAS of inverse-dynamics
% identification of the Kapitsa pendulum.
% The script uses the function file INVD_ID.

clear
x_0=[.1 0 0 -1 .1 0 0 0 .1 0 0]';
tspan=[0 .5];
g=9.81;
l=0.7;
A_1=0.4;
A_2=2;
A_3=3;
nu=0.05;
delta=0.05;
[t,x]=ode23s('invd_id',tspan,x_0);
u='A_1+A_2*cos(t/(2*nu))+A_3*sin(t/nu)';
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);
end
plot(t,y_a,'--',t,eval(u))
set(gca,'Fontsize',12)
legend('adaline output','plant input')
%hold
%plot(t,zeros(1,length(t)))
xlabel('Time (sec)','Fontsize',12)
ylabel('Plant and adaline outputs','Fontsize',12)
title('Inverse dynamics identification---Section 9.2','Fontsize',12)
grid
%hold