描述
Consider the AC circuit below. We will assume that the circuit is in steady-state. Thus, the voltage at nodes 1 and 2 are given by v1= VScoswt and v2= VRcos (wt + q) where VSis the voltage of the source, wis the frequency (in radians per second), and t is time. VRis the magnitude of the voltage drop across the resistor, and qis its phase.
考虑下面的交流电路。我们假设电路处于稳态。因此,节点1和2的电压由 v1 = VScoswt 和 v2 = VRcos (wt + q)给出,其中 VSIS 是源的电压,是频率(以弧度每秒为单位) ,t 是时间。VRis 通过电阻器的电压降的大小,并且 qis 它的相位。
You are to write a program to determine VRfor different values of w. You will need two laws of electricity to solve this problem. The first is Ohm's Law, which states v2= iR where i is the current in the circuit, oriented clockwise. The second is i = C d/dt (v1-v2) which relates the current to the voltage on either side of the capacitor. "d/dt"indicates the derivative with respect to t.
你要编写一个程序来确定不同的 w 值的 VR。你将需要两个电学定律来解决这个问题。第一个是欧姆定律,它指出 v2 = iR,其中 i 是电路中顺时针方向的电流。第二个是 i = Cd/dt (v1-v2) ,它将电流与电容器两侧的电压联系起来。“ d/dt”表示关于 t 的导数。
输入
The input will consist of one or more lines. The first line contains three real numbers and a non-negative integer. The real numbers are VS, R, and C, in that order. The integer, n, is the number of test cases. The following n lines of the input will have one real number per line. Each of these numbers is the angular frequency, w.
For each angular frequency in the input you are to output its corresponding VR on a single line. Each VR value output should be rounded to three digits after the decimal point.
输入将由一行或多行组成。第一行包含三个实数和一个非负整数。实数是 VS,R 和 C,按照这个顺序。整数 n 是测试用例的数量。下面的 n 行输入每行有一个实数。每个数字都是角频率 w。
输出对于输入中的每个角频率,你都要在一行中输出相应的虚拟现实。每个 VR 值的输出应四舍五入到小数点后的三位数字。
样例输入
1.0 1.0 1.0 9
0.01
0.031623
0.1
0.31623
1.0
3.1623
10.0
31.623
100.0
样例输出
0.010
0.032
0.100
0.302
0.707
0.953
0.995
1.000
1.000
提示
// 浮点数输入输出示例
C/C++:
#include
#include
#include
using namespace std;
int main() {
double v;
scanf("%lf", &v);
printf("%.3f\n", v);
cin >> v;
cout << std::fixed << setprecision(3) << v << endl;
return 0;
}
Pascal:
writeln(v:0:3);
来源
Greater New York 2001
分析
此题虽然给出的是物理背景,但其实是一道数学题(?)。
VR公式的推导:
V2 = iR = CR d/dt (VS*cos(wt)-VR*cos(wt+q))=VRcos(wt+q)
= CR w (sin(wt+q)-sin(wt))=VRcos(wt+q)
下面用到高中数学当中的计算方法,分别令 t=0 和 wt+q=0 ,得到 CRw tan b = 1 和 VR=CRw VS sin b ,
然后利用三角函数中的万能公式,求得 :VR = CRw VS / sqrt (1+ (CRw) ^ 2 ))
代码
#include<iostream>
#include<iomanip>
using namespace std;
#include<cmath>
int main()
{
double Vs;
double R;
double C;
int n;
double w;
double result[10];
cin >> Vs >> R >> C >> n;
for (int i = 0; i < n; ++i)
{
cin>>w;
w = R*C*w;
result[i] = w*Vs/sqrt(1+w*w);
}
for (int j= 0; j < n; ++j)
{
cout << setiosflags(ios::fixed) << setprecision(3) << result[j] << endl;
}
return 0;
}
给个赞和关注吧