%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Integracion numerica de una ecuacion diferencial
% por el metodo de Euler de 1er. orden
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Circuito RC serie
% q: carga del capacitor
% u: tension de entrada
% uc: tension en el capacitor
% Modelo en TD
% q(k)= (1-T/(R*C))*q(k-1)+(T/R)*u(k-1)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
R=1e6;  % Resistencia en Ohms
C=1e-6; % Capacidad en Faradios
q(1)=0;
T=0.01; % Paso de Integracion
u=[ones(300,1);zeros(300,1)];  % pulso rectangular
for k=2:600
    q(k)=(1-T/(R*C))*q(k-1)+(T/R)*u(k-1);
end
uc=q/C;
t=[0:T:599*T]';  % eje tiempo en seg.
plot(t,uc)
