%charging a capacitor

%Generator voltage
U = 12
%Capacitance
C = 1e-3
%Res
R = 10
tau = (R*C)

%Tolerance
%u -> U as t -> inf,
%therefore we need to introduce an arbitrary stop point.
%The "tolerance" below is the percentage of U to reach.
%A value of "1" is undefined.
tol = 0.999
endtime = tau*log(1/(1-tol))

%appropiate timescale
t = 0:endtime/100:endtime;

%fcn
x = U*(1-exp(-t/tau))

plot (t, x)
hold on
plot(tau, U*(1-exp(-1)), 'ro')

%pretty text
str=['\leftarrowTau = ', num2str(tau), ', ', num2str(U*(1-exp(-1)))];
text(tau + 0.2*tau, U*(1-exp(-1)), str)
