-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRCApp.java
More file actions
38 lines (31 loc) · 1.04 KB
/
Copy pathRCApp.java
File metadata and controls
38 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.io.*;
import java.util.*;
public class RCApp {
public static void main(String[] args) throws FileNotFoundException{
PrintStream output = new PrintStream(new File ("Voltagese.txt"));
Scanner sc = new Scanner(new File("inputs.txt"));
double R = returnValue(sc);
double C = returnValue(sc);
double Q0 = returnValue(sc);
double t = 0;
double tau = R*C;
double IR = Q0*(-1/tau)*Math.pow(Math.E, (-t/tau));
double VR = IR*R;
double VC = Q0/C;
double VS = R*C*(VC/t)+VC;
for(int i = 0; i < 150; i++){
//discharge of capacitor
IR = Q0*(-1/tau)*Math.pow(Math.E, (-t/tau));
VR = VR + IR*R;
VC = VC + Q0/C;
VS = VS + (VC+VR);
t ++;
output.printf(" %3f %3f \n", t, VR);
}
}
public static double returnValue(Scanner sc){
double dummy = sc.nextDouble();
sc.nextLine();
return dummy;
}
}