# u can change the input type and response by uncommenting 
## t the stions of the code that are below each subplot 
clear; clc;
pkg load control;
K = 32.3;
s = tf('s');
#openLoopTf = K/( s*(s+3)*(s+6));
openLoopTf = (24.4*s  + 24.4 *0.1) / (s*(s+3)*(s+6)*(s))
#openLoopTf = 1 / (s*(s+3)*(s+6)*(s))
#openLoopTf = 10* ( s^4 +18*s^3 +97*s^2+180*s+100) / (s*(s+3)*(s+6)*(s^2))
#nn=poly([ -5 -2 -10 -1])

G_tclosed = feedback(openLoopTf,1)

error_tf = 1/(1+openLoopTf)
input = tf(1,1)
rows = 3;
cols = 3;
u = step(input,1:50).'; 
u(1) = 0;
t = 0:1:length(u)-1;

subplot(rows,cols,1);
step(input, "m");
title("The step input");

 subplot(rows, cols, 2);
 ramp(input, "m");
 title("Ramp input");

subplot(rows, cols,3);
parabolaInput = 0.5.*u.*t.^2;
plot(t, parabolaInput, "m");
title("Parobolic input");
ylabel("y");
xlabel("Time s");
legend("input");
grid on;


subplot(rows, cols,4);
step(G_tclosed, "r");
title("system step respones");

 subplot(rows, cols,5);
# ramp(G_tclosed, "r");
 step(G_tclosed * (1/s),"r")
 title("Ramp respones");

subplot(rows, cols,6)
#[y_out, time] = lsim(G_tclosed, parabolaInput, t);
[y_out, time] = step(G_tclosed * (1/s^2), t);
plot(time,y_out, "r");
title("Parabolic response");grid on;
xlabel("Time s");
ylabel("y");
grid on;



subplot(rows, cols,7);
step(error_tf);
title("Error to step input");
grid on;

 subplot(rows, cols,8);
 rampInput = t;
# ramp(error_tf);
 step(error_tf * (1/s))
 title("Error to ramp input");
 grid on;

subplot(rows, cols,9);
#[y_outError, time] = lsim(error_tf, parabolaInput, t);
[y_outError, time] = step(error_tf * (1/s^2), t);
plot(t,y_outError); 
title("System error to parabolic response");
xlabel("Time s");
ylabel("y");
grid on

ee=parabolaInput .- y_out';
figure()
plot(t,ee,t,y_out,t,parabolaInput)