%% circuit example from lecture

R = 2
L = 2
C = 1

%% should be less than 1, complex case
whichcase = R^2*C / (4*L)

b = sqrt(1/(C*L) - R^2/(4*L^2))
lam1 = -R/(2*L) + 1i*b
lam2 = -R/(2*L) - 1i*b

%% double check:
A = [-R/L 1/L; -1/C 0]

[V, D] = eig(A)

%% scale eigenvalues to something human
v1 = V(:,1) / V(2,1)
v2 = V(:,2) / V(2,1)

%% ... some work by hand in lecture notes ...
% we found the real general solution, then matched
% to the initial condition.

%% Plots
% There is decay, and some oscillation too---maybe a different choice
% of parameters with larger b compared to the real part would the
% oscillations more obvious.
t = linspace(0, 12, 1000);
V = exp(-t/2) .* (cos(t/2) + sin(t/2));
I = exp(-t/2) .* sin(t/2);
figure(1); clf;
plot(t, V, 'b-', 'linewidth', 3);
hold on
plot(t, I, 'r-', 'linewidth', 3);
xlabel('t')
legend('V(t)', 'I(t)')
