clear; clc;
% this program computes resonance of RLC circuit
R = 5;      % Ohms
L = 20e-3;  % H
C = 400e-6; % F
Us = 100;   % V
% vector of frequencies logarithmically equally spaced
% 1000 points between decades 10^0 and 10^5
w=logspace(0,5,1000);
% complex impedances
ZR=R; ZL=j*w*L;
ZC=1./(j*w*C); Z=ZR+ZL+ZC;
% current and voltages
I=Us./Z; UR=ZR.*I; UL=ZL.*I; UC=ZC.*I;
disp('The resonance frequency is'); wr=1/sqrt(L*C)
disp('The quality factor is'); Qr=wr*L/R
% graph
semilogx(w,abs(I),'linewidth',2);
xlabel('\omega [rad/s]'); ylabel('current magnitude [A]');
grid on;
