I just can't find the correct solution to the following, pretty basic problem:
A capacitor \$C\$ is continuously discharged by a resistor \$R\$. This is easily described by an exponential decay (\$\tau:= RC\$): $$ U_C(t)=U_{C,0}\exp(-t\tau^{-1}) $$
Hence, a time \$t_1\$ can be calculated at which the voltage reaches a specific, lower voltage \$U_1\$: $$ t_1 = -\tau\ln(U_1/U_{C,0}) $$
Now consider a sinusoidal voltage source which, as its voltages increases over time, will reach the voltage of the discharging capacitor and will thus recharge it. I'm searching for this exact moment in time \$t_2\$.
My Approach: Equating the capacitor discharge formula and the given voltage function: $$ \hat{U}\sin(\omega t_2) = U_{C,0}\exp(-t_2\tau^{-1}) $$ Using Euler's Formula yields $$ -\mathrm{i}\hat{U}\exp(\mathrm{i}\omega t_2) = U_{C,0}\exp(-t_2\tau^{-1})\\ \Longrightarrow\ \exp(\mathrm{i}\omega t_2+t_2\tau^{-1})=\mathrm{i}U_{C,0}/\hat{U}\\ \Longrightarrow\ \mathrm{i}\omega t_2+t_2\tau^{-1}=\ln(\mathrm{i}U_{C,0}/\hat{U}) $$ Using the complex logarithm gives $$ \mathrm{i}\omega t_2+t_2\tau^{-1}=\ln(U_{C,0}/\hat{U})+\mathrm{i}\arg(\mathrm{i}U_{C,0}/\hat{U})\\ \Longleftrightarrow\mathrm{i}\omega t_2+t_2\tau^{-1}=\ln(U_{C,0}/\hat{U})-\mathrm{i}(\pi/2+2k\pi) $$ Since we don't leave the first periodicity (\$0\$ to \$2\pi\$) \$k=0\$ should be applicable. We also expand the denominator: $$ t_2=\frac{(\ln(U_{C,0}/\hat{U})-\mathrm{i}\pi/2)(\tau^{-1}-\mathrm{i}\omega)}{\omega^2+\tau^{-2}} $$ Only considering the real parts again yields $$ t_2=\frac{\tau^{-1}\ln(U_{C,0}/\hat{U})-\omega\pi/2}{\omega^2+\tau^{-2}} $$ which sadly only returns unrealistic values in my simulation.
How can I find \$t_2\$ correctly?
Example: As requested, a short example is presented below. In this case \$U_e=\hat{U}\sin(\omega t)\$ is the input voltage used above. However, \$R_1\$ is the charging resistor and is not considered here as there already is a simple approximate for the time \$t_1\$ when the capacitor stops charging. Thus, \$R:=R_2\$ was used in my description above.
I've marked the time \$t_2\$ at which I want to re-apply the current charge function which already is implemented for the first part (\$t<t_1\$) of the capactior voltage function. The "finished simulation" would inlcude an alternation of charging (cap. voltage increases) and discharging (cap. voltage drops).
Regarding Jan's Answer:
I've plotted the given equation, which seems to lack an expected exponential decay: Using the following component values resulted in the following simulation result:
Even though the extreme values seem to somewhat match, I'm really at a loss why your solution doesn't give the same result.