-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocusPlotter.java
More file actions
118 lines (95 loc) · 2.34 KB
/
LocusPlotter.java
File metadata and controls
118 lines (95 loc) · 2.34 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* By Magdalen Berns 2012.
*/
import java.io.*;
public class LocusPlotter{
/*
* instance variable
*/
private final double Re = 3.4;
private final double T = 2.5;
private final double Rm = 1.2;
private final double Le = Math.pow(10,-4);
private final double Cm = 1.1 * Math.pow(10,-4);
private final double Lm = 4.7 * Math.pow(10,-3);
private double a;
private String file;
/*
* zero-arg class constructor to initialize instance variables
*/
public LocusPlotter(){
/*
* preach to the converted
*/
file=null;
a=0.0;
}
/*
* argument set number to multiply by fundimental period.
* has been hard coded to 1 in main for this task.
*/
public void setOutPut(double n) throws IOException {
/*
*
* local variables
*
*/
double step = 0.1;
double period = Math.PI*2;
double t = 0;
double omegaMax=314000;
double omega=0;
/*instantiate file output object */
PrintWriter fout = new PrintWriter(new FileWriter(file));
/*
* Calculate the value of the function, with y the reactive and x the resistive
*
*/
while (omega <= omegaMax){
if(omega>125){
setA(Cm,omega, Lm);
double x = resitive(Re, T, Rm, omega);
double y= reactive(T, Rm, Le, omega);
fout.println(x + " " + y);
}
omega =omega + (period * step);
}
//print statement and close output file
System.out.println("\nxmgrace " + file + "\n");
fout.close();
}
public double resitive(double Re, double T, double Rm, double omega){
return Re + (( T * T * Rm) /(( Rm * Rm ) + a * a));
}
public double reactive(double T, double Rm, double Le, double omega){
return omega * Le + ((T * T * a) / ((Rm * Rm) +(a * a) ));
}
public void setA(double Cm, double omega, double Lm){
a = (1/(omega* Cm)-omega * Lm);
}
public double getA(){
return a;
}
/*
Main Methodßås
*/
public void setFileName(String aFile){
this.file=aFile;
}
/*All seeing main method */
public static void main(String[] argv) throws IOException {
/*
*make sure that a filename was read into commandline
*/
if(argv.length!=0){
LocusPlotter hp = new LocusPlotter();
//the input string of first agument becomes name of output file
hp.setFileName(argv[0]);
hp.setOutPut(1);
}
/*
* if not file name was typed in data won't get printed.
*/
else return;
}
}