function transient_analysis_02
% Transient analysis of RC circuit
ts=0;   % start time
te=0.4; % end time
x0=0;   % initial condition
[t,x]=ode23(@diffeq,[ts te],x0);
% numerical solution
subplot(1,2,1); plot(t,x);
xlabel('t [s]'); ylabel('uC(t) [V]');
title('State variable approach'); grid on;
% analytical solution
R=10000; C=10e-6; Us=10;
uc=Us*(1-exp(-t/(R*C)));
subplot(1,2,2); plot(t,uc);
xlabel('t [s]'); ylabel('uC(t) [V]');
title('Analytical approach'); grid on;
% differential equation
function dxdt=diffeq(t,x)
R=10000; C=10e-6; Us=10;
A=-1/(R*C);
F=Us/(R*C);
dxdt=A*x+F;
