Solution to POJ 1045

The problem is on here.

Analysis

It is hard to go with the direct fomular, because there is no build-in way to
calculate a differential. However, we can apporach it with the defination of
differential: $\frac{df(x)}{dx} = \lim_{\Delta x \to +\infty}\frac{f(x+\Delta x)-f(x)}{\Delta x}$. Usually make $\Delta x$ equal to DOUBLE_EPSILON.

The first thing we should do is to simplification the fomulars. From $v_1=V_S\cos{\omega t}$, $v_2=V_R\cos(\omega t + \theta)$, $v_2=iR$, and $i=C\frac{d(v_1-v_2)}{dt}$, we could come out an equation shown below:

$$V_R\cos(\omega t+\theta)=CR(\frac{d v_1}{dt}-\frac{d v_2}{dt})$$

After simplification, it would turn into the equation shown below:

$$V_R\cos(\omega t+\theta)=\omega CR[V_R\sin(\omega t+\theta)-V_S\sin{\omega t}]$$

When $\omega t+\theta=0$, it would show us:

$$V_R=\omega CRV_S\sin\theta$$

When $\omega t=0$, it would show us:

$$V_R\cos\theta=\omega CRV_R\sin\theta$$

which would further lead to $\tan\theta=\frac{1}{\omega CR}$.

As a consequence, we know how to calculate $V_R$.

Easy Solution

#include <cstdio>
#include <cmath>

int main(void)
{
double Vs, R, C;
int n;
scanf("%lf%lf%lf%d", &Vs, &R, &C, &n);
while(n--) {
double omega;
scanf("%lf", &omega);
double CRw = C * R * omega;
double phi = atan(1.0 / CRw);
printf("%.3lf\n", CRw * Vs * sin(phi));
}
return 0;
}

Please pay more attention about “… output should be rounded to three digits after the decimal point.”.