echo on
close all
%--------------------------------------------------------------------------
% 2. gykorló feladat megoldása
%--------------------------------------------------------------------------
%
R = 10;
C = 1e-3;
L = 100e-3;
%
a = [0 1;-1/L/C -R/L];
b = [0 1/L/C]';
c = [1 0; 0 R*C; -1 -R*C; 0 C];
d = [0 0 1 0]';
%
sys = ss(a,b,c,d)
%
%--------------------------------------------------------------------------
% a)
%--------------------------------------------------------------------------
%
eig(a)
%
%--------------------------------------------------------------------------
% b)
%--------------------------------------------------------------------------
%
x0 = [1 1]';
[y,t,x] = initial(sys,x0);
subplot(2,1,1); plot(t,x(:,1)); grid; ylabel('x_1(t)');
title('Sajátmozgás')
subplot(2,1,2); plot(t,x(:,2)); grid; ylabel('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);
subplot(4,1,1); plot(t,y(:,1)); grid; ylabel('u_C(t)');
title('Egységimpulzus válasz')
subplot(4,1,2); plot(t,y(:,2)); grid; ylabel('u_R(t)');
subplot(4,1,3); plot(t,y(:,3)); grid; ylabel('u_L(t)');
subplot(4,1,4); plot(t,y(:,4)); grid; ylabel('i(t)');
xlabel('t[sec]');
%
figure;
[y,t,x] = step(sys);
subplot(4,1,1); plot(t,y(:,1)); grid; ylabel('u_C(t)');
title('Egységugrás válasz')
oo=ones(1,length(t));
hold
plot(t,y(end,1)*1.05*oo,'r',t,y(end,1)*0.95*oo,'r')
hold off
subplot(4,1,2); plot(t,y(:,2)); grid; ylabel('u_R(t)');
subplot(4,1,3); plot(t,y(:,3)); grid; ylabel('u_L(t)');
subplot(4,1,4); plot(t,y(:,4)); grid; ylabel('i(t)');
xlabel('t[sec]');
%
% Túllendülés
max(y(:,1))-y(end,1)
% Beállási idõ
echo off
for ii = length(t):-1:1
    if abs(y(ii,1)-y(end,1)) > (y(end,1)*.05)         
        break;
    end;
end;
%
echo on
t(ii)
%
%--------------------------------------------------------------------------
% d)
%--------------------------------------------------------------------------
%
figure
t = 0:.001:1;
x0 = [0 0]';
u = exp(-2*t).*sin(15*t);
[y,t,x] = lsim(sys,u,t,x0);
subplot(4,1,1); plot(t,y(:,1)); grid; ylabel('u_C(t)');
title('Kimeneti jel: x_0 = [0 0] esetén')
subplot(4,1,2); plot(t,y(:,2)); grid; ylabel('u_R(t)');
subplot(4,1,3); plot(t,y(:,3)); grid; ylabel('u_L(t)');
subplot(4,1,4); plot(t,y(:,4)); grid; ylabel('i(t)');
xlabel('t[sec]');
figure
plot(x(:,1),x(:,2)); grid;
title('Állapottrajektória: x_0 = [0 0]'); xlabel('x_1'); ylabel('x_2')
%
figure
x0 = [1 1]';
[y,t,x] = lsim(sys,u,t,x0);
subplot(4,1,1); plot(t,y(:,1)); grid; ylabel('u_C(t)');
title('Kimeneti jel: x_0 = [1 1] esetén')
subplot(4,1,2); plot(t,y(:,2)); grid; ylabel('u_R(t)');
subplot(4,1,3); plot(t,y(:,3)); grid; ylabel('u_L(t)');
subplot(4,1,4); plot(t,y(:,4)); grid; ylabel('i(t)');
xlabel('t[sec]');
figure
plot(x(:,1),x(:,2)); grid;
title('Állapottrajektória: x_0 = [1 1]'); xlabel('x_1'); ylabel('x_2')
echo off

