% MR726 - komplex sajatertekekkel es valosakkal
clear all
clc

R = 0.5;
L=1;
C = 1;

A = [-2*R/L 1/L;-1/C -2/(R*C)];
B = [0;1/(R*C)];
CT = [2*R 0];
D = 0;

[m,la] = eig(A)
U0 = 10;
XG = A \ (-B*U0)

kv = m \ (-XG)
k1 = kv(1);k2=kv(2); m1 = m(:,1); m2 = m(:,2);
la1 = la(1,1); la2 = la(2,2);
xe11 = k1*m1(1); xe12 = k2*m2(1); 
xe21 = k1*m1(2); xe22 = k2*m2(2);

%% allapotvaltozok abrazolasa
t = -0.1:0.001:5;
x1 = stepfun(t,0).*(xe11*exp(la1*t) + xe12 *exp(la2*t) + XG(1));
x2 = stepfun(t,0).*(xe21*exp(la1*t) + xe22 *exp(la2*t) + XG(2));
figure;
  plot(t,x1,'r--', t,x2, 'k--', 'LineWidth',2);
  xlabel('t'); ylabel('x'); title('MR726 - allapotvaltozok');

%% Komplex sajatertekek esete
clear all
clc

R = 1;
L = 1;
C = 1;
A = [-2*R/L 1/L;-1/C -2/(R*C)];
B = [0;1/(R*C)];
CT = [2*R 0];
D = 0;
[m,la] = eig(A)
U0 = 1;
XG = A \ (-B*U0)
kv = m \ (-XG)
k1 = kv(1);k2=kv(2); 
m1 = m(:,1); m2 = m(:,2);
la1 = la(1,1); la2 = la(2,2);
xe11 = k1*m1(1); xe12 = k2*m2(1); 
xe21 = k1*m1(2); xe22 = k2*m2(2);

%% 
t = -0.1:0.001:5;
x1 = stepfun(t,0).*(xe11*exp(la1*t) + xe12 *exp(la2*t) + XG(1));
x2 = stepfun(t,0).*(xe21*exp(la1*t) + xe22 *exp(la2*t) + XG(2));
figure;
  plot(t,x1,'r--', t,x2, 'k--', 'LineWidth',2);
  xlabel('t'); ylabel('x'); title('MR726 - allapotvaltozok');
