echo on
close all
%--------------------------------------------------------------------------
% 1. gykorló feladat megoldása
%--------------------------------------------------------------------------
%
k = 1;
m = .1;
b = 1;
%
A = [0 1;-k/m -b/m];
B = [0 1/m]';
C = [1 0];
D = 0;
%
sys = ss(A,B,C,D)
%
%--------------------------------------------------------------------------
% a)
%--------------------------------------------------------------------------
%
eig(A)
%
%--------------------------------------------------------------------------
% b)
%--------------------------------------------------------------------------
%
x0 = [1 0]';
[y,t,x] = initial(sys,x0);
plot(t,x); grid; ylabel('x(t)');
title('Sajátmozgás'); legend('x_1(t)','x_2(t)')
xlabel('t[sec]');
figure
plot(x(:,1),x(:,2)); grid;
title('Állapottrajektória'); xlabel('x_1'); ylabel('x_2')
%
%--------------------------------------------------------------------------
% c)
%--------------------------------------------------------------------------
%
figure;
[y,t,x] = impulse(sys);
plot(t,y); grid; ylabel('y(t)');
title('Egységimpulzus válasz: k = 1')
xlabel('t[sec]');
%
figure;
[y,t,x] = step(sys);
plot(t,y); grid; ylabel('y(t)');
title('Egységugrás válasz: k = 1')
xlabel('t[sec]');
%
%--------------------------------------------------------------------------
% d)
%--------------------------------------------------------------------------
%
k = 1;
m = .1;
b = .1;
%
A = [0 1;-k/m -b/m];
B = [0 1/m]';
C = [1 0];
D = 0;
%
sys = ss(A,B,C,D)
%
figure;
[y,t,x] = impulse(sys);
plot(t,y); grid; ylabel('y(t)');
title('Egységimpulzus válasz: k = 0.1')
xlabel('t[sec]');
%
figure;
[y,t,x] = step(sys);
plot(t,y); grid; ylabel('y(t)');
title('Egységugrás válasz: k = 0.1')
xlabel('t[sec]');
hold
oo=ones(1,length(t));
plot(t,y(end)*1.05*oo,'r',t,y(end)*0.95*oo,'r')
hold off
%
% A túllendülés 
max(y)-y(end)
%
% Beállási idõ
echo off
for ii = length(t):-1:1
    if abs(y(ii)-y(end)) > (y(end)*.05)         
        break;
    end;
end;
%
echo on
t(ii+1)
echo off

