1 | /*
|
---|
2 | * Class Phasor
|
---|
3 | *
|
---|
4 | * Defines a Phasor and includes
|
---|
5 | * the methods needed for standard Phasor arithmetic
|
---|
6 | *
|
---|
7 | * See PhasorMatrix for creation and manipulatioin of matrices of phasors
|
---|
8 | *
|
---|
9 | * WRITTEN BY: Dr Michael Thomas Flanagan
|
---|
10 | *
|
---|
11 | * DATE: 4 July 2007
|
---|
12 | * AMENDED: 17 april 2008
|
---|
13 | *
|
---|
14 | * DOCUMENTATION:
|
---|
15 | * See Michael T Flanagan's Java library on-line web pages:
|
---|
16 | * http://www.ee.ucl.ac.uk/~mflanaga/java/
|
---|
17 | * http://www.ee.ucl.ac.uk/~mflanaga/java/Phasor.html
|
---|
18 | *
|
---|
19 | * Copyright (c) 2007 - 2008 Michael Thomas Flanagan
|
---|
20 | *
|
---|
21 | * PERMISSION TO COPY:
|
---|
22 | *
|
---|
23 | * Permission to use, copy and modify this software and its documentation for NON-COMMERCIAL purposes is granted, without fee,
|
---|
24 | * provided that an acknowledgement to the author, Dr Michael Thomas Flanagan at www.ee.ucl.ac.uk/~mflanaga, appears in all copies
|
---|
25 | * and associated documentation or publications.
|
---|
26 | *
|
---|
27 | * Redistributions of the source code of this source code, or parts of the source codes, must retain the above copyright notice, this list of conditions
|
---|
28 | * and the following disclaimer and requires written permission from the Michael Thomas Flanagan:
|
---|
29 | *
|
---|
30 | * Redistribution in binary form of all or parts of this class must reproduce the above copyright notice, this list of conditions and
|
---|
31 | * the following disclaimer in the documentation and/or other materials provided with the distribution and requires written permission from the Michael Thomas Flanagan:
|
---|
32 | *
|
---|
33 | * Dr Michael Thomas Flanagan makes no representations about the suitability or fitness of the software for any or for a particular purpose.
|
---|
34 | * Dr Michael Thomas Flanagan shall not be liable for any damages suffered as a result of using, modifying or distributing this software
|
---|
35 | * or its derivatives.
|
---|
36 | *
|
---|
37 | ***************************************************************************************/
|
---|
38 |
|
---|
39 | package agents.anac.y2015.agentBuyogV2.flanagan.circuits;
|
---|
40 |
|
---|
41 | import agents.anac.y2015.agentBuyogV2.flanagan.complex.Complex;
|
---|
42 | import agents.anac.y2015.agentBuyogV2.flanagan.math.Fmath;
|
---|
43 |
|
---|
44 | public class Phasor{
|
---|
45 |
|
---|
46 | private double magnitude = 0.0D; // magnitude of the Phasor
|
---|
47 | private double phaseInDeg = 0.0D; // phase of the Phasor in degrees
|
---|
48 | private double phaseInRad = 0.0D; // phase of the Phasor in degrees
|
---|
49 | private Complex rectangular = new Complex(0.0, 0.0); // rectangular complex equivalent of the Phasor
|
---|
50 |
|
---|
51 | // frequency - static to prevent inappropriate combination of phasors
|
---|
52 | private static double frequency = Double.NaN; // frequency in Hz
|
---|
53 | private static double omega = Double.NaN; // radial frequency
|
---|
54 |
|
---|
55 |
|
---|
56 |
|
---|
57 | // CONSTRUCTORS
|
---|
58 | // default constructor
|
---|
59 | public Phasor(){
|
---|
60 | }
|
---|
61 |
|
---|
62 | // Constructor setting magnitude and phase in degrees
|
---|
63 | public Phasor(double magnitude, double phase){
|
---|
64 | this.magnitude = magnitude;
|
---|
65 | this.phaseInDeg = phase;
|
---|
66 | this.phaseInRad = Math.toRadians(phase);
|
---|
67 | this.rectangular.polar(this.magnitude, this.phaseInRad);
|
---|
68 | }
|
---|
69 |
|
---|
70 | // Constructor setting magnitude only
|
---|
71 | public Phasor(double magnitude){
|
---|
72 | this.magnitude = magnitude;
|
---|
73 | this.rectangular.polar(this.magnitude, this.phaseInRad);
|
---|
74 | }
|
---|
75 |
|
---|
76 | // SET VALUES
|
---|
77 | // Set the frequency in Hz - as a static variable
|
---|
78 | public static void setFrequency(double freq){
|
---|
79 | if(Fmath.isNaN(Phasor.frequency)){
|
---|
80 | Phasor.frequency = freq;
|
---|
81 | Phasor.omega = 2.0D*Math.PI*freq;
|
---|
82 |
|
---|
83 | }
|
---|
84 | else{
|
---|
85 | throw new IllegalArgumentException("You have already entered a value for the frequency, " + Phasor.frequency + ", that differs from the one you are now attempting to enter, " + freq);
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | // Set the radial frequency - as a static variable
|
---|
90 | public static void setRadialFrequency(double omega){
|
---|
91 | if(Fmath.isNaN(Phasor.omega)){
|
---|
92 | Phasor.omega = omega;
|
---|
93 | Phasor.frequency = Phasor.omega/(2.0D*Math.PI);
|
---|
94 | }
|
---|
95 | else{
|
---|
96 | throw new IllegalArgumentException("You have already entered a value for the radial frequency, omega, " + Phasor.omega + ", that differs from the one you are now attempting to enter, " + omega);
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | // Set the value of magnitude
|
---|
101 | public void setMagnitude(double magnitude){
|
---|
102 | this.magnitude = magnitude;
|
---|
103 | this.rectangular.polar(this.magnitude, this.phaseInRad);
|
---|
104 | }
|
---|
105 |
|
---|
106 | // Set the value of phase in degrees
|
---|
107 | public void setPhaseInDegrees(double phase){
|
---|
108 | this.phaseInDeg = phase;
|
---|
109 | this.phaseInRad = Math.toRadians(phase);
|
---|
110 | this.rectangular.polar(this.magnitude, this.phaseInRad);
|
---|
111 | }
|
---|
112 |
|
---|
113 |
|
---|
114 | // Set the values of magnitude and phase in degrees
|
---|
115 | public void reset(double magnitude, double phaseInDegrees){
|
---|
116 | this.magnitude = magnitude;
|
---|
117 | this.phaseInDeg = phaseInDegrees;
|
---|
118 | this.phaseInRad = Math.toRadians(phaseInDegrees);
|
---|
119 | this.rectangular.polar(this.magnitude, this.phaseInRad);
|
---|
120 | }
|
---|
121 |
|
---|
122 |
|
---|
123 | // GET VALUES
|
---|
124 | // Get the frequency in Hz
|
---|
125 | public static double getFrequency(){
|
---|
126 | return Phasor.frequency;
|
---|
127 | }
|
---|
128 |
|
---|
129 | // Get the radial frequency
|
---|
130 | public static double setRadialFrequency(){
|
---|
131 | return Phasor.omega;
|
---|
132 | }
|
---|
133 |
|
---|
134 | // Get the value of magnitude
|
---|
135 | public double getMagnitude(){
|
---|
136 | return this.magnitude;
|
---|
137 | }
|
---|
138 |
|
---|
139 | // Get the value of phase in degrees
|
---|
140 | public double getPhaseInDegrees(){
|
---|
141 | return this.phaseInDeg;
|
---|
142 | }
|
---|
143 |
|
---|
144 | // Get the value of phase in radians
|
---|
145 | public double getPhaseInRadians(){
|
---|
146 | return this.phaseInRad;
|
---|
147 | }
|
---|
148 |
|
---|
149 | // Get the real part of the Phasor
|
---|
150 | public double getReal(){
|
---|
151 | return this.magnitude*Math.cos(this.phaseInRad);
|
---|
152 | }
|
---|
153 |
|
---|
154 | // Get the imaginary part of the Phasor
|
---|
155 | public double getImag(){
|
---|
156 | return this.magnitude*Math.sin(this.phaseInRad);
|
---|
157 | }
|
---|
158 |
|
---|
159 | // CONVERSIONS
|
---|
160 |
|
---|
161 | // converts rectangular complex variable to a Phasor
|
---|
162 | public static Phasor toPhasor(Complex cc){
|
---|
163 | Phasor ph = new Phasor();
|
---|
164 | ph.magnitude = cc.abs();
|
---|
165 | ph.phaseInRad = cc.argRad();
|
---|
166 | ph.phaseInDeg = cc.argDeg();
|
---|
167 | ph.rectangular = cc;
|
---|
168 | return ph;
|
---|
169 | }
|
---|
170 |
|
---|
171 | // converts the Phasor to a rectangular complex variable
|
---|
172 | public Complex toRectangular(){
|
---|
173 | Complex cc = new Complex();
|
---|
174 | cc.polar(this.magnitude, this.phaseInRad);
|
---|
175 | return cc;
|
---|
176 | }
|
---|
177 |
|
---|
178 | // converts the Phasor to a rectangular complex variable - static method
|
---|
179 | public static Complex toRectangular(Phasor ph){
|
---|
180 | Complex cc = new Complex();
|
---|
181 | cc.polar(ph.magnitude, ph.phaseInRad);
|
---|
182 | return cc;
|
---|
183 | }
|
---|
184 |
|
---|
185 | // converts the Phasor to a rectangular complex variable
|
---|
186 | public Complex toComplex(){
|
---|
187 | Complex cc = new Complex();
|
---|
188 | cc.polar(this.magnitude, this.phaseInRad);
|
---|
189 | return cc;
|
---|
190 | }
|
---|
191 |
|
---|
192 | // converts the Phasor to a rectangular complex variable - static method
|
---|
193 | public static Complex toComplex(Phasor ph){
|
---|
194 | Complex cc = new Complex();
|
---|
195 | cc.polar(ph.magnitude, ph.phaseInRad);
|
---|
196 | return cc;
|
---|
197 | }
|
---|
198 |
|
---|
199 | // Format a phasor number as a string, 'magnitude''<''phase''deg' - phase in degrees
|
---|
200 | // Overides java.lang.String.toString()
|
---|
201 | // instance method
|
---|
202 | public String toString(){
|
---|
203 | return this.magnitude + "<" + this.phaseInDeg + "deg";
|
---|
204 | }
|
---|
205 |
|
---|
206 | // Format a phasor number as a string, 'magnitude''<''phase''deg' - phase in degrees
|
---|
207 | // Overides java.lang.String.toString()
|
---|
208 | // static method
|
---|
209 | public static String toString(Phasor ph){
|
---|
210 | return ph.magnitude + "<" + ph.phaseInDeg + "deg";
|
---|
211 | }
|
---|
212 |
|
---|
213 |
|
---|
214 | // Parse a string to obtain Phasor
|
---|
215 | // accepts strings:
|
---|
216 | // 'magnitude''<''phase' - phase in degrees
|
---|
217 | // 'magnitude''L''phase' - phase in degrees
|
---|
218 | // 'magnitude''<''phase''deg' - phase in degrees
|
---|
219 | // 'magnitude''L''phase''deg' - phase in degrees
|
---|
220 | // 'magnitude''<''phase''rad' - phase in radians
|
---|
221 | // 'magnitude''L''phase''rad' - phase in radians
|
---|
222 | public static Phasor parsePhasor(String ss){
|
---|
223 | Phasor ph = new Phasor();
|
---|
224 | ss = ss.trim();
|
---|
225 | int anglePos = ss.indexOf('<');
|
---|
226 | if(anglePos==-1){
|
---|
227 | anglePos = ss.indexOf('L');
|
---|
228 | if(anglePos==-1)throw new IllegalArgumentException("no angle symbol, <, in the string, ss");
|
---|
229 | }
|
---|
230 | int degPos = ss.indexOf('d');
|
---|
231 | if(degPos==-1)degPos = ss.indexOf('D');
|
---|
232 | int radPos = ss.indexOf('r');
|
---|
233 | if(radPos==-1)degPos = ss.indexOf('R');
|
---|
234 | String mag = ss.substring(0,anglePos);
|
---|
235 | ph.magnitude = Double.parseDouble(mag);
|
---|
236 | String phas = null;
|
---|
237 | if(degPos!=-1){
|
---|
238 | phas = ss.substring(anglePos+1, degPos);
|
---|
239 | ph.phaseInDeg = Double.parseDouble(mag);
|
---|
240 | ph.phaseInRad = Math.toRadians(ph.phaseInDeg);
|
---|
241 | }
|
---|
242 | if(degPos==-1 && radPos==-1){
|
---|
243 | phas = ss.substring(anglePos+1);
|
---|
244 | ph.phaseInDeg = Double.parseDouble(phas);
|
---|
245 | ph.phaseInRad = Math.toRadians(ph.phaseInDeg);
|
---|
246 | }
|
---|
247 | if(radPos!=-1){
|
---|
248 | phas = ss.substring(anglePos+1, radPos);
|
---|
249 | ph.phaseInRad = Double.parseDouble(phas);
|
---|
250 | ph.phaseInDeg = Math.toDegrees(ph.phaseInRad);
|
---|
251 | }
|
---|
252 | ph.rectangular.polar(ph.magnitude, ph.phaseInRad);
|
---|
253 |
|
---|
254 | return ph;
|
---|
255 | }
|
---|
256 |
|
---|
257 | // Same method as parsePhasor
|
---|
258 | // Overides java.lang.Object.valueOf()
|
---|
259 | public static Phasor valueOf(String ss){
|
---|
260 | return Phasor.parsePhasor(ss);
|
---|
261 | }
|
---|
262 |
|
---|
263 | // INPUT AND OUTPUT
|
---|
264 |
|
---|
265 | // READ A PHASOR
|
---|
266 | // Read a Phasor from the keyboard console after a prompt message
|
---|
267 | // in a String format compatible with Phasor.parse,
|
---|
268 | // 'magnitude'<'phase', 'magnitude'<'phase'deg, 'magnitude'<'phase'rad
|
---|
269 | // e.g. 1.23<34.1deg, -0.67<-56.7, 6.8e2<-0.22rad
|
---|
270 | // prompt = Prompt message to vdu
|
---|
271 | public static final synchronized Phasor readPhasor(String prompt){
|
---|
272 | int ch = ' ';
|
---|
273 | String phstring = "";
|
---|
274 | boolean done = false;
|
---|
275 |
|
---|
276 | System.out.print(prompt + " ");
|
---|
277 | System.out.flush();
|
---|
278 |
|
---|
279 | while (!done){
|
---|
280 | try{
|
---|
281 | ch = System.in.read();
|
---|
282 | if (ch < 0 || (char)ch == '\n')
|
---|
283 | done = true;
|
---|
284 | else
|
---|
285 | phstring = phstring + (char) ch;
|
---|
286 | }
|
---|
287 | catch(java.io.IOException e){
|
---|
288 | done = true;
|
---|
289 | }
|
---|
290 | }
|
---|
291 | return Phasor.parsePhasor(phstring);
|
---|
292 | }
|
---|
293 |
|
---|
294 | // Read a Phasor from the keyboard console after a prompt message (with String default option)
|
---|
295 | // in a String format compatible with Phasor.parse,
|
---|
296 | // 'magnitude'<'phase', 'magnitude'<'phase'deg, 'magnitude'<'phase'rad
|
---|
297 | // e.g. 1.23<34.1deg, -0.67<-56.7, 6.8e2<-0.22rad
|
---|
298 | // prompt = Prompt message to vdu
|
---|
299 | // dflt = default value
|
---|
300 | public static final synchronized Phasor readPhasor(String prompt, String dflt){
|
---|
301 | int ch = ' ';
|
---|
302 | String phstring = "";
|
---|
303 | boolean done = false;
|
---|
304 |
|
---|
305 | System.out.print(prompt + " [default value = " + dflt + "] ");
|
---|
306 | System.out.flush();
|
---|
307 |
|
---|
308 | int i=0;
|
---|
309 | while (!done){
|
---|
310 | try{
|
---|
311 | ch = System.in.read();
|
---|
312 | if (ch < 0 || (char)ch == '\n' || (char)ch =='\r'){
|
---|
313 | if(i==0){
|
---|
314 | phstring = dflt;
|
---|
315 | if((char)ch == '\r')ch = System.in.read();
|
---|
316 | }
|
---|
317 | done = true;
|
---|
318 | }
|
---|
319 | else{
|
---|
320 | phstring = phstring + (char) ch;
|
---|
321 | i++;
|
---|
322 | }
|
---|
323 | }
|
---|
324 | catch(java.io.IOException e){
|
---|
325 | done = true;
|
---|
326 | }
|
---|
327 | }
|
---|
328 | return Phasor.parsePhasor(phstring);
|
---|
329 | }
|
---|
330 |
|
---|
331 | // Read a Phasor from the keyboard console after a prompt message (with Phasor default option)
|
---|
332 | // in a String format compatible with Phasor.parse,
|
---|
333 | // 'magnitude'<'phase', 'magnitude'<'phase'deg, 'magnitude'<'phase'rad
|
---|
334 | // e.g. 1.23<34.1deg, -0.67<-56.7, 6.8e2<-0.22rad
|
---|
335 | // prompt = Prompt message to vdu
|
---|
336 | // dflt = default value
|
---|
337 | public static final synchronized Phasor readPhasor(String prompt, Phasor dflt)
|
---|
338 | {
|
---|
339 | int ch = ' ';
|
---|
340 | String phstring = "";
|
---|
341 | boolean done = false;
|
---|
342 |
|
---|
343 | System.out.print(prompt + " [default value = " + dflt + "] ");
|
---|
344 | System.out.flush();
|
---|
345 |
|
---|
346 | int i=0;
|
---|
347 | while (!done){
|
---|
348 | try{
|
---|
349 | ch = System.in.read();
|
---|
350 | if (ch < 0 || (char)ch == '\n' || (char)ch =='\r'){
|
---|
351 | if(i==0){
|
---|
352 | if((char)ch == '\r')ch = System.in.read();
|
---|
353 | return dflt;
|
---|
354 | }
|
---|
355 | done = true;
|
---|
356 | }
|
---|
357 | else{
|
---|
358 | phstring = phstring + (char) ch;
|
---|
359 | i++;
|
---|
360 | }
|
---|
361 | }
|
---|
362 | catch(java.io.IOException e){
|
---|
363 | done = true;
|
---|
364 | }
|
---|
365 | }
|
---|
366 | return Phasor.parsePhasor(phstring);
|
---|
367 | }
|
---|
368 |
|
---|
369 | // Read a Phasor from the keyboard console without a prompt message
|
---|
370 | // in a String format compatible with Phasor.parse,
|
---|
371 | // 'magnitude'<'phase', 'magnitude'<'phase'deg, 'magnitude'<'phase'rad
|
---|
372 | // e.g. 1.23<34.1deg, -0.67<-56.7, 6.8e2<-0.22rad
|
---|
373 | public static final synchronized Phasor readPhasor(){
|
---|
374 | int ch = ' ';
|
---|
375 | String phstring = "";
|
---|
376 | boolean done = false;
|
---|
377 |
|
---|
378 | System.out.print(" ");
|
---|
379 | System.out.flush();
|
---|
380 |
|
---|
381 | while (!done){
|
---|
382 | try{
|
---|
383 | ch = System.in.read();
|
---|
384 | if (ch < 0 || (char)ch == '\n')
|
---|
385 | done = true;
|
---|
386 | else
|
---|
387 | phstring = phstring + (char) ch;
|
---|
388 | }
|
---|
389 | catch(java.io.IOException e){
|
---|
390 | done = true;
|
---|
391 | }
|
---|
392 | }
|
---|
393 | return Phasor.parsePhasor(phstring);
|
---|
394 | }
|
---|
395 |
|
---|
396 |
|
---|
397 | // PRINT A PHASOR
|
---|
398 | // Print to terminal window with text (message) and a line return
|
---|
399 | public void println(String message){
|
---|
400 | System.out.println(message + " " + this.toString());
|
---|
401 | }
|
---|
402 |
|
---|
403 | // Print to terminal window without text (message) but with a line return
|
---|
404 | public void println(){
|
---|
405 | System.out.println(" " + this.toString());
|
---|
406 | }
|
---|
407 |
|
---|
408 | // Print to terminal window with text (message) but without line return
|
---|
409 | public void print(String message){
|
---|
410 | System.out.print(message + " " + this.toString());
|
---|
411 | }
|
---|
412 |
|
---|
413 | // Print to terminal window without text (message) and without line return
|
---|
414 | public void print(){
|
---|
415 | System.out.print(" " + this.toString());
|
---|
416 | }
|
---|
417 |
|
---|
418 | // PRINT AN ARRAY OF PHASORS
|
---|
419 | // Print an array to terminal window with text (message) and a line return
|
---|
420 | public static void println(String message, Phasor[] aa){
|
---|
421 | System.out.println(message);
|
---|
422 | for(int i=0; i<aa.length; i++){
|
---|
423 | System.out.println(aa[i].toString() + " ");
|
---|
424 | }
|
---|
425 | }
|
---|
426 |
|
---|
427 | // Print an array to terminal window without text (message) but with a line return
|
---|
428 | public static void println(Phasor[] aa){
|
---|
429 | for(int i=0; i<aa.length; i++){
|
---|
430 | System.out.println(aa[i].toString() + " ");
|
---|
431 | }
|
---|
432 | }
|
---|
433 |
|
---|
434 | // Print an array to terminal window with text (message) but no line returns except at the end
|
---|
435 | public static void print(String message, Phasor[] aa){
|
---|
436 | System.out.print(message+ " ");
|
---|
437 | for(int i=0; i<aa.length; i++){
|
---|
438 | System.out.print(aa[i].toString() + " ");
|
---|
439 | }
|
---|
440 | System.out.println();
|
---|
441 | }
|
---|
442 |
|
---|
443 | // Print an array to terminal window without text (message) but with no line returns except at the end
|
---|
444 | public static void print(Phasor[] aa){
|
---|
445 | for(int i=0; i<aa.length; i++){
|
---|
446 | System.out.print(aa[i].toString() + " ");
|
---|
447 | }
|
---|
448 | System.out.println();
|
---|
449 | }
|
---|
450 |
|
---|
451 | // TRUNCATION
|
---|
452 | // Rounds the mantissae of both the magnitude and phase to prec places - instance
|
---|
453 | public Phasor truncate(int prec){
|
---|
454 | if(prec<0)return this;
|
---|
455 |
|
---|
456 | double xMa = this.magnitude;
|
---|
457 | double xPd = this.phaseInDeg;
|
---|
458 | double xPr = this.phaseInRad;
|
---|
459 | Complex xRect = this.rectangular;
|
---|
460 |
|
---|
461 | Phasor y = new Phasor();
|
---|
462 |
|
---|
463 | y.magnitude = Fmath.truncate(xMa, prec);
|
---|
464 | y.phaseInDeg = Fmath.truncate(xPd, prec);
|
---|
465 | y.phaseInRad = Fmath.truncate(xPr, prec);
|
---|
466 | y.rectangular = Complex.truncate(xRect, prec);
|
---|
467 |
|
---|
468 | return y;
|
---|
469 | }
|
---|
470 |
|
---|
471 | // Rounds the mantissae of both the magnitude and phase to prec places - static
|
---|
472 | public static Phasor truncate(Phasor ph, int prec){
|
---|
473 | if(prec<0)return ph;
|
---|
474 |
|
---|
475 | double xMa = ph.magnitude;
|
---|
476 | double xPd = ph.phaseInDeg;
|
---|
477 | double xPr = ph.phaseInRad;
|
---|
478 | Complex xRect = ph.rectangular;
|
---|
479 |
|
---|
480 | Phasor y = new Phasor();
|
---|
481 |
|
---|
482 | y.magnitude = Fmath.truncate(xMa, prec);
|
---|
483 | y.phaseInDeg = Fmath.truncate(xPd, prec);
|
---|
484 | y.phaseInRad = Fmath.truncate(xPr, prec);
|
---|
485 | y.rectangular = Complex.truncate(xRect, prec);
|
---|
486 |
|
---|
487 | return y;
|
---|
488 | }
|
---|
489 |
|
---|
490 |
|
---|
491 | // HASH CODE
|
---|
492 |
|
---|
493 | // Return a HASH CODE for the Phasor
|
---|
494 | // Overides java.lang.Object.hashCode()
|
---|
495 | public int hashCode(){
|
---|
496 | long lmagnt = Double.doubleToLongBits(this.magnitude);
|
---|
497 | long lphase = Double.doubleToLongBits(this.phaseInDeg);
|
---|
498 | int hmagnt = (int)(lmagnt^(lmagnt>>>32));
|
---|
499 | int hphase = (int)(lphase^(lphase>>>32));
|
---|
500 | return 6*(hmagnt/10)+4*(hphase/10);
|
---|
501 | }
|
---|
502 |
|
---|
503 |
|
---|
504 | // ARRAYS
|
---|
505 |
|
---|
506 | // Create a one dimensional array of Phasors of length n
|
---|
507 | // all magnitudes = 1 and all phases = 0
|
---|
508 | public static Phasor[] oneDarray(int n){
|
---|
509 | Phasor[] a = new Phasor[n];
|
---|
510 | Phasor b = new Phasor();
|
---|
511 | b.reset(1.0, 0.0);
|
---|
512 | for(int i=0; i<n; i++){
|
---|
513 | a[i] = b;
|
---|
514 | }
|
---|
515 | return a;
|
---|
516 | }
|
---|
517 |
|
---|
518 | // Create a one dimensional array of Phasor objects of length n
|
---|
519 | // all magnitudes = a and all phases = b
|
---|
520 | public static Phasor[] oneDarray(int n, double a, double b){
|
---|
521 | Phasor[] phArray = new Phasor[n];
|
---|
522 | Phasor ph = new Phasor();
|
---|
523 | ph.reset(a, b);
|
---|
524 | for(int i=0; i<n; i++){
|
---|
525 | phArray[i] = ph;
|
---|
526 | }
|
---|
527 | return phArray;
|
---|
528 | }
|
---|
529 |
|
---|
530 |
|
---|
531 | // Create a one dimensional array of Phasors of length n
|
---|
532 | // all = the Phasor constant
|
---|
533 | public static Phasor[] oneDarray(int n, Phasor constant){
|
---|
534 | Phasor[] ph =new Phasor[n];
|
---|
535 | for(int i=0; i<n; i++){
|
---|
536 | ph[i] = constant.copy();
|
---|
537 | }
|
---|
538 | return ph;
|
---|
539 | }
|
---|
540 |
|
---|
541 | // Create a two dimensional array of Phasors of dimensions n and m
|
---|
542 | // all magnitudes = unity and all phases = zero
|
---|
543 | public static Phasor[][] twoDarray(int n, int m){
|
---|
544 | Phasor[][] phArray = new Phasor[n][m];
|
---|
545 | Phasor ph = new Phasor();
|
---|
546 | ph.reset(1.0, 0.0);
|
---|
547 | for(int i=0; i<n; i++){
|
---|
548 | for(int j=0; j<m; j++){
|
---|
549 | phArray[i][j] = ph;
|
---|
550 | }
|
---|
551 | }
|
---|
552 | return phArray;
|
---|
553 | }
|
---|
554 |
|
---|
555 | // Create a two dimensional array of Phasors of dimensions n and m
|
---|
556 | // all magnitudes = a and all phases = b
|
---|
557 | public static Phasor[][] twoDarray(int n, int m, double a, double b){
|
---|
558 | Phasor[][] phArray = new Phasor[n][m];
|
---|
559 | Phasor ph = new Phasor();
|
---|
560 | ph.reset(a, b);
|
---|
561 | for(int i=0; i<n; i++){
|
---|
562 | for(int j=0; j<m; j++){
|
---|
563 | phArray[i][j] = ph;
|
---|
564 | }
|
---|
565 | }
|
---|
566 | return phArray;
|
---|
567 | }
|
---|
568 |
|
---|
569 | // Create a two dimensional array of Phasors of dimensions n and m
|
---|
570 | // all = the Phasor constant
|
---|
571 | public static Phasor[][] twoDarray(int n, int m, Phasor constant){
|
---|
572 | Phasor[][]phArray =new Phasor[n][m];
|
---|
573 | for(int i=0; i<n; i++){
|
---|
574 | for(int j=0; j<m; j++){
|
---|
575 | phArray[i][j] = constant.copy();
|
---|
576 | }
|
---|
577 | }
|
---|
578 | return phArray;
|
---|
579 |
|
---|
580 | }
|
---|
581 |
|
---|
582 | // Create a three dimensional array of Phasorss of dimensions n, m and l
|
---|
583 | // all magnitudes = unity and all phaes = zero
|
---|
584 | public static Phasor[][][] threeDarray(int n, int m, int l){
|
---|
585 | Phasor[][][] phArray = new Phasor[n][m][l];
|
---|
586 | Phasor ph = new Phasor();
|
---|
587 | ph.reset(1.0, 0.0);
|
---|
588 | for(int i=0; i<n; i++){
|
---|
589 | for(int j=0; j<m; j++){
|
---|
590 | for(int k=0; k<l; k++){
|
---|
591 | phArray[i][j][k] = ph;
|
---|
592 | }
|
---|
593 | }
|
---|
594 | }
|
---|
595 | return phArray;
|
---|
596 | }
|
---|
597 |
|
---|
598 | // Create a three dimensional array of Phasorss of dimensions n, m and l
|
---|
599 | // all magnitudes = a and all phases = b
|
---|
600 | public static Phasor[][][] threeDarray(int n, int m, int l, double a, double b){
|
---|
601 | Phasor[][][] phArray = new Phasor[n][m][l];
|
---|
602 | Phasor ph = new Phasor();
|
---|
603 | ph.reset(a, b);
|
---|
604 | for(int i=0; i<n; i++){
|
---|
605 | for(int j=0; j<m; j++){
|
---|
606 | for(int k=0; k<l; k++){
|
---|
607 | phArray[i][j][k] = ph;
|
---|
608 | }
|
---|
609 | }
|
---|
610 | }
|
---|
611 | return phArray;
|
---|
612 | }
|
---|
613 |
|
---|
614 | // Create a three dimensional array of Phasors of dimensions n, m and l
|
---|
615 | // all = the Phasor constant
|
---|
616 | public static Phasor[][][] threeDarray(int n, int m, int l, Phasor constant){
|
---|
617 | Phasor[][][] phArray = new Phasor[n][m][l];
|
---|
618 | for(int i=0; i<n; i++){
|
---|
619 | for(int j=0; j<m; j++){
|
---|
620 | for(int k=0; k<l; k++){
|
---|
621 | phArray[i][j][k] = constant.copy();
|
---|
622 | }
|
---|
623 | }
|
---|
624 | }
|
---|
625 | return phArray;
|
---|
626 | }
|
---|
627 |
|
---|
628 | // COPY
|
---|
629 |
|
---|
630 | // Copy a single Phasor [instance method]
|
---|
631 | public Phasor copy(){
|
---|
632 | if(this==null){
|
---|
633 | return null;
|
---|
634 | }
|
---|
635 | else{
|
---|
636 | Phasor b = new Phasor();
|
---|
637 | b.magnitude = this.magnitude;
|
---|
638 | b.phaseInDeg = this.phaseInDeg;
|
---|
639 | b.phaseInRad = this.phaseInRad;
|
---|
640 | return b;
|
---|
641 | }
|
---|
642 | }
|
---|
643 |
|
---|
644 | // Copy a single Phasor [static method]
|
---|
645 | public static Phasor copy(Phasor ph){
|
---|
646 | if(ph==null){
|
---|
647 | return null;
|
---|
648 | }
|
---|
649 | else{
|
---|
650 | Phasor b = new Phasor();
|
---|
651 | b.magnitude = ph.magnitude;
|
---|
652 | b.phaseInDeg = ph.phaseInDeg;
|
---|
653 | b.phaseInRad = ph.phaseInRad;
|
---|
654 | return b;
|
---|
655 | }
|
---|
656 | }
|
---|
657 |
|
---|
658 | // Copy a 1D array of Phasors (deep copy)
|
---|
659 | public static Phasor[] copy(Phasor[] a){
|
---|
660 | if(a==null){
|
---|
661 | return null;
|
---|
662 | }
|
---|
663 | else{
|
---|
664 | int n =a.length;
|
---|
665 | Phasor[] b = Phasor.oneDarray(n);
|
---|
666 | for(int i=0; i<n; i++){
|
---|
667 | b[i] = a[i].copy();
|
---|
668 | }
|
---|
669 | return b;
|
---|
670 | }
|
---|
671 | }
|
---|
672 |
|
---|
673 | // Copy a 2D array of Phasors (deep copy)
|
---|
674 | public static Phasor[][] copy(Phasor[][] a){
|
---|
675 | if(a==null){
|
---|
676 | return null;
|
---|
677 | }
|
---|
678 | else{
|
---|
679 | int n =a.length;
|
---|
680 | int m =a[0].length;
|
---|
681 | Phasor[][] b = Phasor.twoDarray(n, m);
|
---|
682 | for(int i=0; i<n; i++){
|
---|
683 | for(int j=0; j<m; j++){
|
---|
684 | b[i][j] = a[i][j].copy();
|
---|
685 | }
|
---|
686 | }
|
---|
687 | return b;
|
---|
688 | }
|
---|
689 | }
|
---|
690 |
|
---|
691 | // Copy a 3D array of Phasors (deep copy)
|
---|
692 | public static Phasor[][][] copy(Phasor[][][] a){
|
---|
693 | if(a==null){
|
---|
694 | return null;
|
---|
695 | }
|
---|
696 | else{
|
---|
697 | int n = a.length;
|
---|
698 | int m = a[0].length;
|
---|
699 | int l = a[0][0].length;
|
---|
700 | Phasor[][][] b = Phasor.threeDarray(n, m, l);
|
---|
701 | for(int i=0; i<n; i++){
|
---|
702 | for(int j=0; j<m; j++){
|
---|
703 | for(int k=0; k<l; k++){
|
---|
704 | b[i][j][k] = a[i][j][k].copy();
|
---|
705 | }
|
---|
706 | }
|
---|
707 | }
|
---|
708 | return b;
|
---|
709 | }
|
---|
710 | }
|
---|
711 |
|
---|
712 | // CLONE
|
---|
713 | // Overrides Java.Object method clone
|
---|
714 | // Copy a single Phasor
|
---|
715 | public Object clone(){
|
---|
716 | Object ret = null;
|
---|
717 |
|
---|
718 | if(this!=null){
|
---|
719 | Phasor b = new Phasor();
|
---|
720 | b.magnitude = this.magnitude;
|
---|
721 | b.phaseInDeg = this.phaseInDeg;
|
---|
722 | b.phaseInRad = this.phaseInRad;
|
---|
723 | ret = (Object)b;
|
---|
724 | }
|
---|
725 |
|
---|
726 | return ret;
|
---|
727 | }
|
---|
728 |
|
---|
729 | // ADDITION
|
---|
730 |
|
---|
731 | // Add a Phasor to this Phasor
|
---|
732 | // this Phasor remains unaltered
|
---|
733 | public Phasor plus(Phasor ph){
|
---|
734 | Complex com1 = this.toRectangular();
|
---|
735 | Complex com2 = ph.toRectangular();
|
---|
736 | Complex com3 = com1.plus(com2);
|
---|
737 | return Phasor.toPhasor(com3);
|
---|
738 | }
|
---|
739 |
|
---|
740 | // Add a complex number to this Phasor
|
---|
741 | // this Phasor remains unaltered
|
---|
742 | public Phasor plus(Complex com1){
|
---|
743 | Phasor ph = new Phasor();
|
---|
744 | Complex com2 = this.toRectangular();
|
---|
745 | Complex com3 = com1.plus(com2);
|
---|
746 | return Phasor.toPhasor(com3);
|
---|
747 | }
|
---|
748 |
|
---|
749 | // Add a Phasor to this Phasor and replace this with the sum
|
---|
750 | public void plusEquals(Phasor ph1 ){
|
---|
751 | Complex com1 = this.toRectangular();
|
---|
752 | Complex com2 = ph1.toRectangular();
|
---|
753 | Complex com3 = com1.plus(com2);
|
---|
754 | Phasor ph2 = Phasor.toPhasor(com3);
|
---|
755 | this.magnitude = ph2.magnitude;
|
---|
756 | this.phaseInDeg = ph2.phaseInDeg;
|
---|
757 | this.phaseInRad = ph2.phaseInRad;
|
---|
758 | }
|
---|
759 |
|
---|
760 | // Add complex number to this Phasor and replace this with the sum
|
---|
761 | public void plusEquals(Complex com1 ){
|
---|
762 | Complex com2 = this.toRectangular();
|
---|
763 | Complex com3 = com1.plus(com2);
|
---|
764 | Phasor ph2 = Phasor.toPhasor(com3);
|
---|
765 | this.magnitude += ph2.magnitude;
|
---|
766 | this.phaseInDeg += ph2.phaseInDeg;
|
---|
767 | this.phaseInRad += ph2.phaseInRad;
|
---|
768 | }
|
---|
769 |
|
---|
770 | // SUBTRACTION
|
---|
771 |
|
---|
772 | // Subtract a Phasor from this Phasor
|
---|
773 | // this Phasor remains unaltered
|
---|
774 | public Phasor minus(Phasor ph){
|
---|
775 | Complex com1 = this.toRectangular();
|
---|
776 | Complex com2 = ph.toRectangular();
|
---|
777 | Complex com3 = com1.minus(com2);
|
---|
778 | return Phasor.toPhasor(com3);
|
---|
779 | }
|
---|
780 |
|
---|
781 | // Subtract a complex number from this Phasor
|
---|
782 | // this Phasor remains unaltered
|
---|
783 | public Phasor minus(Complex com1){
|
---|
784 | Phasor ph = new Phasor();
|
---|
785 | Complex com2 = this.toRectangular();
|
---|
786 | Complex com3 = com1.minus(com2);
|
---|
787 | return Phasor.toPhasor(com3);
|
---|
788 | }
|
---|
789 |
|
---|
790 | // Subtract a Phasor from this Phasor and replace this with the difference
|
---|
791 | public void minusEquals(Phasor ph1 ){
|
---|
792 | Complex com1 = this.toRectangular();
|
---|
793 | Complex com2 = ph1.toRectangular();
|
---|
794 | Complex com3 = com1.plus(com2);
|
---|
795 | Phasor ph2 = Phasor.toPhasor(com3);
|
---|
796 | this.magnitude = ph2.magnitude;
|
---|
797 | this.phaseInDeg = ph2.phaseInDeg;
|
---|
798 | this.phaseInRad = ph2.phaseInRad;
|
---|
799 | }
|
---|
800 |
|
---|
801 | // Subtract a complex number from this Phasor and replace this with the difference
|
---|
802 | public void minusEquals(Complex com1 ){
|
---|
803 | Complex com2 = this.toRectangular();
|
---|
804 | Complex com3 = com1.plus(com2);
|
---|
805 | Phasor ph2 = Phasor.toPhasor(com3);
|
---|
806 | this.magnitude = ph2.magnitude;
|
---|
807 | this.phaseInDeg = ph2.phaseInDeg;
|
---|
808 | this.phaseInRad = ph2.phaseInRad;
|
---|
809 | }
|
---|
810 |
|
---|
811 | // MULTIPLICATION
|
---|
812 |
|
---|
813 | // Multiplies a Phasor by this Phasor
|
---|
814 | // this Phasor remains unaltered
|
---|
815 | public Phasor times(Phasor ph1){
|
---|
816 | Phasor ph2 = new Phasor();
|
---|
817 | double mag = this.magnitude*ph1.magnitude;
|
---|
818 | double pha = this.phaseInDeg + ph1.phaseInDeg;
|
---|
819 | ph2.reset(mag, pha);
|
---|
820 | return ph2;
|
---|
821 | }
|
---|
822 |
|
---|
823 | // Multiplies this Phasor by a Complex number
|
---|
824 | // this Phasor remains unaltered
|
---|
825 | public Phasor times(Complex com1){
|
---|
826 | Phasor ph1 = Phasor.toPhasor(com1);
|
---|
827 | Phasor ph2 = new Phasor();
|
---|
828 | double mag = this.magnitude*ph1.magnitude;
|
---|
829 | double pha = this.phaseInDeg + ph1.phaseInDeg;
|
---|
830 | ph2.reset(mag, pha);
|
---|
831 | return ph2;
|
---|
832 | }
|
---|
833 |
|
---|
834 | // Multiplies this Phasor by a double
|
---|
835 | // this Phasor remains unaltered
|
---|
836 | public Phasor times(double constant){
|
---|
837 | Phasor ph2 = new Phasor();
|
---|
838 | double mag = this.magnitude*constant;
|
---|
839 | double pha = this.phaseInDeg;
|
---|
840 | ph2.reset(mag, pha);
|
---|
841 | return ph2;
|
---|
842 | }
|
---|
843 |
|
---|
844 | // Multiplies this Phasor by an int
|
---|
845 | // this Phasor remains unaltered
|
---|
846 | public Phasor times(int constant){
|
---|
847 | Phasor ph2 = new Phasor();
|
---|
848 | double mag = this.magnitude*constant;
|
---|
849 | double pha = this.phaseInDeg;
|
---|
850 | ph2.reset(mag, pha);
|
---|
851 | return ph2;
|
---|
852 | }
|
---|
853 |
|
---|
854 | // Multiplies this Phasor by exp(omega.time)
|
---|
855 | // this Phasor remains unaltered
|
---|
856 | public Phasor timesExpOmegaTime(double omega, double time){
|
---|
857 | if(Fmath.isNaN(Phasor.omega)){
|
---|
858 | Phasor.omega = omega;
|
---|
859 | Phasor.frequency = Phasor.omega/(2.0D*Math.PI);
|
---|
860 | }
|
---|
861 | else{
|
---|
862 | throw new IllegalArgumentException("You have already entered a value for the radial frequency, omega, " + Phasor.omega + ", that differs from the one you are now attempting to enter, " + omega);
|
---|
863 | }
|
---|
864 | Phasor ph2 = new Phasor();
|
---|
865 | ph2.reset(this.magnitude, this.phaseInDeg + Math.toDegrees(omega*time));
|
---|
866 | return ph2;
|
---|
867 | }
|
---|
868 |
|
---|
869 | // Multiplies this Phasor by exp(2.pi.frequency.time)
|
---|
870 | // this Phasor remains unaltered
|
---|
871 | public Phasor timesExpTwoPiFreqTime(double frequency, double time){
|
---|
872 | if(Fmath.isNaN(Phasor.frequency)){
|
---|
873 | Phasor.frequency = frequency;
|
---|
874 | Phasor.omega = Phasor.frequency*2.0D*Math.PI;
|
---|
875 | }
|
---|
876 | else{
|
---|
877 | throw new IllegalArgumentException("You have already entered a value for the frequency, " + Phasor.frequency + ", that differs from the one you are now attempting to enter, " + frequency);
|
---|
878 | }
|
---|
879 | Phasor ph2 = new Phasor();
|
---|
880 | ph2.reset(this.magnitude, this.phaseInDeg + Math.toDegrees(2.0D*Math.PI*frequency*time));
|
---|
881 | return ph2;
|
---|
882 | }
|
---|
883 |
|
---|
884 | // Multiply a Phasor by this Phasor and replace this with the product
|
---|
885 | public void timesEquals(Phasor ph1 ){
|
---|
886 | this.magnitude *= ph1.magnitude;
|
---|
887 | this.phaseInDeg += ph1.phaseInDeg;
|
---|
888 | this.phaseInRad += ph1.phaseInRad;
|
---|
889 | }
|
---|
890 |
|
---|
891 | // Multiply a complex number by this Phasor and replace this with the product
|
---|
892 | public void timesEquals(Complex com1 ){
|
---|
893 | Phasor ph1 = Phasor.toPhasor(com1);
|
---|
894 | this.magnitude *= ph1.magnitude;
|
---|
895 | this.phaseInDeg += ph1.phaseInDeg;
|
---|
896 | this.phaseInRad += ph1.phaseInRad;
|
---|
897 | }
|
---|
898 |
|
---|
899 | // Multiply a double by this Phasor and replace this with the product
|
---|
900 | public void timesEquals(double constant ){
|
---|
901 | this.magnitude *= constant;
|
---|
902 | }
|
---|
903 |
|
---|
904 | // Multiply an int by this Phasor and replace this with the product
|
---|
905 | public void timesEquals(int constant ){
|
---|
906 | this.magnitude *= (double)constant;
|
---|
907 | }
|
---|
908 |
|
---|
909 | // Multiply exp(omega.time) by this Phasor and replace this with the product
|
---|
910 | public void timesEqualsOmegaTime(double omega, double time ){
|
---|
911 | if(Fmath.isNaN(Phasor.omega)){
|
---|
912 | Phasor.omega = omega;
|
---|
913 | Phasor.frequency = Phasor.omega/(2.0D*Math.PI);
|
---|
914 | }
|
---|
915 | else{
|
---|
916 | throw new IllegalArgumentException("You have already entered a value for radial frequency, omega, " + Phasor.omega + ", that differs from the one you are now attempting to enter, " + omega);
|
---|
917 | }
|
---|
918 | this.phaseInRad += omega*time;
|
---|
919 | this.phaseInDeg = Math.toDegrees(this.phaseInRad);
|
---|
920 | }
|
---|
921 |
|
---|
922 | // Multiply exp(2.pi.frequency.time) by this Phasor and replace this with the product
|
---|
923 | public void timesEqualsTwoPiFreqTime(double frequency, double time ){
|
---|
924 | if(Fmath.isNaN(Phasor.frequency)){
|
---|
925 | Phasor.frequency = frequency;
|
---|
926 | Phasor.omega = Phasor.frequency*2.0D*Math.PI;
|
---|
927 | }
|
---|
928 | else{
|
---|
929 | throw new IllegalArgumentException("You have already entered a value for the frequency, " + Phasor.frequency + ", that differs from the one you are now attempting to enter, " + frequency);
|
---|
930 | }
|
---|
931 | this.phaseInRad += 2.0D*Math.PI*frequency*time;
|
---|
932 | this.phaseInDeg = Math.toDegrees(this.phaseInRad);
|
---|
933 | }
|
---|
934 |
|
---|
935 | // DIVISION
|
---|
936 |
|
---|
937 | // Divides this Phasor by a Phasor
|
---|
938 | // this Phasor remains unaltered
|
---|
939 | public Phasor over(Phasor ph1){
|
---|
940 | Phasor ph2 = new Phasor();
|
---|
941 | double mag = this.magnitude/ph1.magnitude;
|
---|
942 | double pha = this.phaseInDeg - ph1.phaseInDeg;
|
---|
943 | ph2.reset(mag, pha);
|
---|
944 | return ph2;
|
---|
945 | }
|
---|
946 |
|
---|
947 | // Divides this Phasor by a Complex number
|
---|
948 | // this Phasor remains unaltered
|
---|
949 | public Phasor over(Complex com1){
|
---|
950 | Phasor ph1 = Phasor.toPhasor(com1);
|
---|
951 | Phasor ph2 = new Phasor();
|
---|
952 | double mag = this.magnitude/ph1.magnitude;
|
---|
953 | double pha = this.phaseInDeg - ph1.phaseInDeg;
|
---|
954 | ph2.reset(mag, pha);
|
---|
955 | return ph2;
|
---|
956 | }
|
---|
957 |
|
---|
958 | // Divides this Phasor by a double
|
---|
959 | // this Phasor remains unaltered
|
---|
960 | public Phasor over(double constant){
|
---|
961 | Phasor ph2 = new Phasor();
|
---|
962 | double mag = this.magnitude/constant;
|
---|
963 | double pha = this.phaseInDeg;
|
---|
964 | ph2.reset(mag, pha);
|
---|
965 | return ph2;
|
---|
966 | }
|
---|
967 |
|
---|
968 | // Divides this Phasor by an int
|
---|
969 | // this Phasor remains unaltered
|
---|
970 | public Phasor over(int constant){
|
---|
971 | Phasor ph2 = new Phasor();
|
---|
972 | double mag = this.magnitude/constant;
|
---|
973 | double pha = this.phaseInDeg;
|
---|
974 | ph2.reset(mag, pha);
|
---|
975 | return ph2;
|
---|
976 | }
|
---|
977 |
|
---|
978 | // Divide this Phasor by a Phasor and replace this with the quotient
|
---|
979 | public void overEquals(Phasor ph1 ){
|
---|
980 | this.magnitude /= ph1.magnitude;
|
---|
981 | this.phaseInDeg -= ph1.phaseInDeg;
|
---|
982 | this.phaseInRad -= ph1.phaseInRad;
|
---|
983 | }
|
---|
984 |
|
---|
985 | // Divide this Phasor by a complex number and replace this with the quotient
|
---|
986 | public void overEquals(Complex com1 ){
|
---|
987 | Phasor ph1 = Phasor.toPhasor(com1);
|
---|
988 | this.magnitude /= ph1.magnitude;
|
---|
989 | this.phaseInDeg -= ph1.phaseInDeg;
|
---|
990 | this.phaseInRad -= ph1.phaseInRad;
|
---|
991 | }
|
---|
992 |
|
---|
993 | // Divide this Phasor by a double and replace this with the quotient
|
---|
994 | public void overEquals(double constant ){
|
---|
995 | this.magnitude /= constant;
|
---|
996 | }
|
---|
997 |
|
---|
998 | // Divide this Phasor by an int and replace this with the quotient
|
---|
999 | public void overEquals(int constant ){
|
---|
1000 | this.magnitude /= (double)constant;
|
---|
1001 | }
|
---|
1002 |
|
---|
1003 | // FURTHER MATHEMATICAL FUNCTIONS
|
---|
1004 |
|
---|
1005 | // Return the absolute value of the magnitude
|
---|
1006 | // changes the sign of the magnitude
|
---|
1007 | public double abs(){
|
---|
1008 | return Math.abs(this.magnitude);
|
---|
1009 | }
|
---|
1010 |
|
---|
1011 | // Return the phase in radians
|
---|
1012 | // identical method to getPhaseInRadians()
|
---|
1013 | public double argInRadians(){
|
---|
1014 | return this.phaseInRad;
|
---|
1015 | }
|
---|
1016 |
|
---|
1017 | // Return the phase in degrees
|
---|
1018 | // identical method to getPhaseInDegrees()
|
---|
1019 | public double argInDegrees(){
|
---|
1020 | return this.phaseInDeg;
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 | // negates a Phasor
|
---|
1024 | // changes the sign of the magnitude
|
---|
1025 | public Phasor negate(){
|
---|
1026 | Phasor ph = new Phasor();
|
---|
1027 | ph.reset(-this.magnitude, this.phaseInDeg);
|
---|
1028 | return ph;
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | // returns the complex conjugate of the Phasor
|
---|
1032 | public Phasor conjugate(){
|
---|
1033 | Phasor ph = new Phasor();
|
---|
1034 | ph.reset(this.magnitude, -this.phaseInDeg);
|
---|
1035 | return ph;
|
---|
1036 | }
|
---|
1037 |
|
---|
1038 | // inverts the Phasor
|
---|
1039 | public Phasor inverse(){
|
---|
1040 | Phasor ph = new Phasor();
|
---|
1041 | ph.reset(1.0D/this.magnitude, -this.phaseInDeg);
|
---|
1042 | return ph;
|
---|
1043 | }
|
---|
1044 |
|
---|
1045 | // Roots
|
---|
1046 | // square root of a Phasor
|
---|
1047 | public static Phasor sqrt(Phasor ph1){
|
---|
1048 | Phasor ph2 = new Phasor();
|
---|
1049 | ph2.reset(Math.sqrt(ph1.magnitude), ph1.phaseInDeg/2.0D);
|
---|
1050 | return ph2;
|
---|
1051 | }
|
---|
1052 |
|
---|
1053 | // nth root of a Phasor
|
---|
1054 | public static Phasor nthRoot(Phasor ph1, int n){
|
---|
1055 | if(n<=0)throw new IllegalArgumentException("The root, " + n + ", must be greater than zero");
|
---|
1056 | Phasor ph2 = new Phasor();
|
---|
1057 | ph2.reset(Math.pow(ph1.magnitude, 1.0/n), ph1.phaseInDeg/n);
|
---|
1058 | return ph2;
|
---|
1059 | }
|
---|
1060 |
|
---|
1061 | // Powers
|
---|
1062 | // square of a Phasor
|
---|
1063 | public static Phasor square(Phasor ph1){
|
---|
1064 | Phasor ph2 = new Phasor();
|
---|
1065 | ph2.reset(Fmath.square(ph1.magnitude), 2.0D*ph1.phaseInDeg);
|
---|
1066 | return ph2;
|
---|
1067 | }
|
---|
1068 |
|
---|
1069 | // nth power of a Phasor - int n
|
---|
1070 | public static Phasor pow(Phasor ph1, int n){
|
---|
1071 | Phasor ph2 = new Phasor();
|
---|
1072 | ph2.reset(Math.pow(ph1.magnitude, n), n*ph1.phaseInDeg);
|
---|
1073 | return ph2;
|
---|
1074 | }
|
---|
1075 |
|
---|
1076 | // nth power of a Phasor - double n
|
---|
1077 | public static Phasor pow(Phasor ph1, double n){
|
---|
1078 | Phasor ph2 = new Phasor();
|
---|
1079 | ph2.reset(Math.pow(ph1.magnitude, n), n*ph1.phaseInDeg);
|
---|
1080 | return ph2;
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 | // nth power of a Phasor - Complex n
|
---|
1084 | public static Phasor pow(Phasor ph1, Complex n){
|
---|
1085 | Complex com1 = ph1.toRectangular();
|
---|
1086 | Complex com2 = Complex.pow(com1, n);
|
---|
1087 | Phasor ph2 = Phasor.toPhasor(com2);
|
---|
1088 | return ph2;
|
---|
1089 | }
|
---|
1090 |
|
---|
1091 | // nth power of a Phasor - Phasor n
|
---|
1092 | public static Phasor pow(Phasor ph1, Phasor n){
|
---|
1093 | Complex com1 = ph1.toRectangular();
|
---|
1094 | Complex comn = n.toRectangular();
|
---|
1095 | Complex com2 = Complex.pow(com1, comn);
|
---|
1096 | Phasor ph2 = Phasor.toPhasor(com2);
|
---|
1097 | return ph2;
|
---|
1098 | }
|
---|
1099 |
|
---|
1100 |
|
---|
1101 | // Exponential of a Phasor
|
---|
1102 | public static Phasor exp(Phasor ph1){
|
---|
1103 | Complex com = ph1.toRectangular();
|
---|
1104 | com = Complex.exp(com);
|
---|
1105 | Phasor ph2 = Phasor.toPhasor(com);
|
---|
1106 | return ph2;
|
---|
1107 | }
|
---|
1108 |
|
---|
1109 | // Natural log of a Phasor
|
---|
1110 | public static Phasor log(Phasor ph1){
|
---|
1111 | Complex com = new Complex(Math.log(ph1.magnitude), ph1.phaseInDeg);
|
---|
1112 | Phasor ph2 = Phasor.toPhasor(com);;
|
---|
1113 | return ph2;
|
---|
1114 | }
|
---|
1115 |
|
---|
1116 | // Trigonometric Functions
|
---|
1117 | // sine
|
---|
1118 | public Phasor sin(Phasor ph1){
|
---|
1119 | Phasor ph2 = new Phasor();
|
---|
1120 | if(ph1.phaseInDeg==0.0){
|
---|
1121 | ph2.reset(Math.sin(ph1.magnitude), 0.0D);
|
---|
1122 | }
|
---|
1123 | else{
|
---|
1124 | Complex com = ph1.toRectangular();
|
---|
1125 | com = Complex.sin(com);
|
---|
1126 | ph2 = Phasor.toPhasor(com);
|
---|
1127 | }
|
---|
1128 |
|
---|
1129 | return ph2;
|
---|
1130 | }
|
---|
1131 |
|
---|
1132 | // cosine
|
---|
1133 | public Phasor cos(Phasor ph1){
|
---|
1134 | Phasor ph2 = new Phasor();
|
---|
1135 | if(ph1.phaseInDeg==0.0){
|
---|
1136 | ph2.reset(Math.cos(ph1.magnitude), 0.0D);
|
---|
1137 | }
|
---|
1138 | else{
|
---|
1139 | Complex com = ph1.toRectangular();
|
---|
1140 | com = Complex.cos(com);
|
---|
1141 | ph2 = Phasor.toPhasor(com);
|
---|
1142 | }
|
---|
1143 |
|
---|
1144 | return ph2;
|
---|
1145 | }
|
---|
1146 |
|
---|
1147 | // tangent
|
---|
1148 | public Phasor tan(Phasor ph1){
|
---|
1149 | Phasor ph2 = new Phasor();
|
---|
1150 | if(ph1.phaseInDeg==0.0){
|
---|
1151 | ph2.reset(Math.tan(ph1.magnitude), 0.0D);
|
---|
1152 | }
|
---|
1153 | else{
|
---|
1154 | Complex com = ph1.toRectangular();
|
---|
1155 | com = Complex.tan(com);
|
---|
1156 | ph2 = Phasor.toPhasor(com);
|
---|
1157 | }
|
---|
1158 |
|
---|
1159 | return ph2;
|
---|
1160 | }
|
---|
1161 |
|
---|
1162 | // cotangent
|
---|
1163 | public Phasor cot(Phasor ph1){
|
---|
1164 | Phasor ph2 = new Phasor();
|
---|
1165 | if(ph1.phaseInDeg==0.0){
|
---|
1166 | ph2.reset(Fmath.cot(ph1.magnitude), 0.0D);
|
---|
1167 | }
|
---|
1168 | else{
|
---|
1169 | Complex com = ph1.toRectangular();
|
---|
1170 | com = Complex.cot(com);
|
---|
1171 | ph2 = Phasor.toPhasor(com);
|
---|
1172 | }
|
---|
1173 |
|
---|
1174 | return ph2;
|
---|
1175 | }
|
---|
1176 |
|
---|
1177 | // secant
|
---|
1178 | public Phasor sec(Phasor ph1){
|
---|
1179 | Phasor ph2 = new Phasor();
|
---|
1180 | if(ph1.phaseInDeg==0.0){
|
---|
1181 | ph2.reset(Fmath.sec(ph1.magnitude), 0.0D);
|
---|
1182 | }
|
---|
1183 | else{
|
---|
1184 | Complex com = ph1.toRectangular();
|
---|
1185 | com = Complex.sec(com);
|
---|
1186 | ph2 = Phasor.toPhasor(com);
|
---|
1187 | }
|
---|
1188 |
|
---|
1189 | return ph2;
|
---|
1190 | }
|
---|
1191 |
|
---|
1192 | // cosecant
|
---|
1193 | public Phasor csc(Phasor ph1){
|
---|
1194 | Phasor ph2 = new Phasor();
|
---|
1195 | if(ph1.phaseInDeg==0.0){
|
---|
1196 | ph2.reset(Fmath.csc(ph1.magnitude), 0.0D);
|
---|
1197 | }
|
---|
1198 | else{
|
---|
1199 | Complex com = ph1.toRectangular();
|
---|
1200 | com = Complex.csc(com);
|
---|
1201 | ph2 = Phasor.toPhasor(com);
|
---|
1202 | }
|
---|
1203 |
|
---|
1204 | return ph2;
|
---|
1205 | }
|
---|
1206 |
|
---|
1207 | // exssecant
|
---|
1208 | public Phasor exsec(Phasor ph1){
|
---|
1209 | Phasor ph2 = new Phasor();
|
---|
1210 | if(ph1.phaseInDeg==0.0){
|
---|
1211 | ph2.reset(Fmath.exsec(ph1.magnitude), 0.0D);
|
---|
1212 | }
|
---|
1213 | else{
|
---|
1214 | Complex com = ph1.toRectangular();
|
---|
1215 | com = Complex.exsec(com);
|
---|
1216 | ph2 = Phasor.toPhasor(com);
|
---|
1217 | }
|
---|
1218 |
|
---|
1219 | return ph2;
|
---|
1220 | }
|
---|
1221 |
|
---|
1222 | // versine
|
---|
1223 | public Phasor vers(Phasor ph1){
|
---|
1224 | Phasor ph2 = new Phasor();
|
---|
1225 | if(ph1.phaseInDeg==0.0){
|
---|
1226 | ph2.reset(Fmath.vers(ph1.magnitude), 0.0D);
|
---|
1227 | }
|
---|
1228 | else{
|
---|
1229 | Complex com = ph1.toRectangular();
|
---|
1230 | com = Complex.vers(com);
|
---|
1231 | ph2 = Phasor.toPhasor(com);
|
---|
1232 | }
|
---|
1233 |
|
---|
1234 | return ph2;
|
---|
1235 | }
|
---|
1236 |
|
---|
1237 | // coversine
|
---|
1238 | public Phasor covers(Phasor ph1){
|
---|
1239 | Phasor ph2 = new Phasor();
|
---|
1240 | if(ph1.phaseInDeg==0.0){
|
---|
1241 | ph2.reset(Fmath.covers(ph1.magnitude), 0.0D);
|
---|
1242 | }
|
---|
1243 | else{
|
---|
1244 | Complex com = ph1.toRectangular();
|
---|
1245 | com = Complex.covers(com);
|
---|
1246 | ph2 = Phasor.toPhasor(com);
|
---|
1247 | }
|
---|
1248 |
|
---|
1249 | return ph2;
|
---|
1250 | }
|
---|
1251 |
|
---|
1252 | // haversine
|
---|
1253 | public Phasor hav(Phasor ph1){
|
---|
1254 | Phasor ph2 = new Phasor();
|
---|
1255 | if(ph1.phaseInDeg==0.0){
|
---|
1256 | ph2.reset(Fmath.hav(ph1.magnitude), 0.0D);
|
---|
1257 | }
|
---|
1258 | else{
|
---|
1259 | Complex com = ph1.toRectangular();
|
---|
1260 | com = Complex.hav(com);
|
---|
1261 | ph2 = Phasor.toPhasor(com);
|
---|
1262 | }
|
---|
1263 |
|
---|
1264 | return ph2;
|
---|
1265 | }
|
---|
1266 |
|
---|
1267 | // hyperbolic sine
|
---|
1268 | public Phasor sinh(Phasor ph1){
|
---|
1269 | Phasor ph2 = new Phasor();
|
---|
1270 | if(ph1.phaseInDeg==0.0){
|
---|
1271 | ph2.reset(Fmath.sinh(ph1.magnitude), 0.0D);
|
---|
1272 | }
|
---|
1273 | else{
|
---|
1274 | Complex com = ph1.toRectangular();
|
---|
1275 | com = Complex.sinh(com);
|
---|
1276 | ph2 = Phasor.toPhasor(com);
|
---|
1277 | }
|
---|
1278 |
|
---|
1279 | return ph2;
|
---|
1280 | }
|
---|
1281 |
|
---|
1282 | // hyperbolic cosine
|
---|
1283 | public Phasor cosh(Phasor ph1){
|
---|
1284 | Phasor ph2 = new Phasor();
|
---|
1285 | if(ph1.phaseInDeg==0.0){
|
---|
1286 | ph2.reset(Fmath.cosh(ph1.magnitude), 0.0D);
|
---|
1287 | }
|
---|
1288 | else{
|
---|
1289 | Complex com = ph1.toRectangular();
|
---|
1290 | com = Complex.cosh(com);
|
---|
1291 | ph2 = Phasor.toPhasor(com);
|
---|
1292 | }
|
---|
1293 |
|
---|
1294 | return ph2;
|
---|
1295 | }
|
---|
1296 |
|
---|
1297 | // hyperbolic secant
|
---|
1298 | public Phasor sech(Phasor ph1){
|
---|
1299 | Phasor ph2 = new Phasor();
|
---|
1300 | if(ph1.phaseInDeg==0.0){
|
---|
1301 | ph2.reset(Fmath.sech(ph1.magnitude), 0.0D);
|
---|
1302 | }
|
---|
1303 | else{
|
---|
1304 | Complex com = ph1.toRectangular();
|
---|
1305 | com = Complex.sech(com);
|
---|
1306 | ph2 = Phasor.toPhasor(com);
|
---|
1307 | }
|
---|
1308 |
|
---|
1309 | return ph2;
|
---|
1310 | }
|
---|
1311 |
|
---|
1312 | // hyperbolic cosecant
|
---|
1313 | public Phasor csch(Phasor ph1){
|
---|
1314 | Phasor ph2 = new Phasor();
|
---|
1315 | if(ph1.phaseInDeg==0.0){
|
---|
1316 | ph2.reset(Fmath.csch(ph1.magnitude), 0.0D);
|
---|
1317 | }
|
---|
1318 | else{
|
---|
1319 | Complex com = ph1.toRectangular();
|
---|
1320 | com = Complex.csch(com);
|
---|
1321 | ph2 = Phasor.toPhasor(com);
|
---|
1322 | }
|
---|
1323 |
|
---|
1324 | return ph2;
|
---|
1325 | }
|
---|
1326 | // Inverse Trigonometric Functions
|
---|
1327 | // inverse sine
|
---|
1328 | public Phasor asin(Phasor ph1){
|
---|
1329 | Phasor ph2 = new Phasor();
|
---|
1330 | if(ph1.phaseInDeg==0.0){
|
---|
1331 | ph2.reset(Math.asin(ph1.getMagnitude()), 0.0D);
|
---|
1332 | }
|
---|
1333 | else{
|
---|
1334 | Complex com = ph1.toRectangular();
|
---|
1335 | com = Complex.asin(com);
|
---|
1336 | ph2 = Phasor.toPhasor(com);
|
---|
1337 | }
|
---|
1338 |
|
---|
1339 | return ph2;
|
---|
1340 | }
|
---|
1341 |
|
---|
1342 | // inverse cosine
|
---|
1343 | public Phasor acos(Phasor ph1){
|
---|
1344 | Phasor ph2 = new Phasor();
|
---|
1345 | if(ph1.phaseInDeg==0.0){
|
---|
1346 | ph2.reset(Math.acos(ph1.magnitude), 0.0D);
|
---|
1347 | }
|
---|
1348 | else{
|
---|
1349 | Complex com = ph1.toRectangular();
|
---|
1350 | com = Complex.acos(com);
|
---|
1351 | ph2 = Phasor.toPhasor(com);
|
---|
1352 | }
|
---|
1353 |
|
---|
1354 | return ph2;
|
---|
1355 | }
|
---|
1356 |
|
---|
1357 | // inverse tangent
|
---|
1358 | public Phasor atan(Phasor ph1){
|
---|
1359 | Phasor ph2 = new Phasor();
|
---|
1360 | if(ph1.phaseInDeg==0.0){
|
---|
1361 | ph2.reset(Math.atan(ph1.magnitude), 0.0D);
|
---|
1362 | }
|
---|
1363 | else{
|
---|
1364 | Complex com = ph1.toRectangular();
|
---|
1365 | com = Complex.atan(com);
|
---|
1366 | ph2 = Phasor.toPhasor(com);
|
---|
1367 | }
|
---|
1368 |
|
---|
1369 | return ph2;
|
---|
1370 | }
|
---|
1371 |
|
---|
1372 | // inverse cotangent
|
---|
1373 | public Phasor acot(Phasor ph1){
|
---|
1374 | Phasor ph2 = new Phasor();
|
---|
1375 | if(ph1.phaseInDeg==0.0){
|
---|
1376 | ph2.reset(Fmath.acot(ph1.magnitude), 0.0D);
|
---|
1377 | }
|
---|
1378 | else{
|
---|
1379 | Complex com = ph1.toRectangular();
|
---|
1380 | com = Complex.acot(com);
|
---|
1381 | ph2 = Phasor.toPhasor(com);
|
---|
1382 | }
|
---|
1383 |
|
---|
1384 | return ph2;
|
---|
1385 | }
|
---|
1386 |
|
---|
1387 | // inverse secant
|
---|
1388 | public Phasor asec(Phasor ph1){
|
---|
1389 | Phasor ph2 = new Phasor();
|
---|
1390 | if(ph1.phaseInDeg==0.0){
|
---|
1391 | ph2.reset(Fmath.asec(ph1.magnitude), 0.0D);
|
---|
1392 | }
|
---|
1393 | else{
|
---|
1394 | Complex com = ph1.toRectangular();
|
---|
1395 | com = Complex.asec(com);
|
---|
1396 | ph2 = Phasor.toPhasor(com);
|
---|
1397 | }
|
---|
1398 |
|
---|
1399 | return ph2;
|
---|
1400 | }
|
---|
1401 |
|
---|
1402 | // inverse cosecant
|
---|
1403 | public Phasor acsc(Phasor ph1){
|
---|
1404 | Phasor ph2 = new Phasor();
|
---|
1405 | if(ph1.phaseInDeg==0.0){
|
---|
1406 | ph2.reset(Fmath.acsc(ph1.magnitude), 0.0D);
|
---|
1407 | }
|
---|
1408 | else{
|
---|
1409 | Complex com = ph1.toRectangular();
|
---|
1410 | com = Complex.acsc(com);
|
---|
1411 | ph2 = Phasor.toPhasor(com);
|
---|
1412 | }
|
---|
1413 |
|
---|
1414 | return ph2;
|
---|
1415 | }
|
---|
1416 |
|
---|
1417 | // inverse exssecant
|
---|
1418 | public Phasor aexsec(Phasor ph1){
|
---|
1419 | Phasor ph2 = new Phasor();
|
---|
1420 | if(ph1.phaseInDeg==0.0){
|
---|
1421 | ph2.reset(Fmath.aexsec(ph1.magnitude), 0.0D);
|
---|
1422 | }
|
---|
1423 | else{
|
---|
1424 | Complex com = ph1.toRectangular();
|
---|
1425 | com = Complex.aexsec(com);
|
---|
1426 | ph2 = Phasor.toPhasor(com);
|
---|
1427 | }
|
---|
1428 |
|
---|
1429 | return ph2;
|
---|
1430 | }
|
---|
1431 |
|
---|
1432 | // inverse versine
|
---|
1433 | public Phasor avers(Phasor ph1){
|
---|
1434 | Phasor ph2 = new Phasor();
|
---|
1435 | if(ph1.phaseInDeg==0.0){
|
---|
1436 | ph2.reset(Fmath.avers(ph1.magnitude), 0.0D);
|
---|
1437 | }
|
---|
1438 | else{
|
---|
1439 | Complex com = ph1.toRectangular();
|
---|
1440 | com = Complex.avers(com);
|
---|
1441 | ph2 = Phasor.toPhasor(com);
|
---|
1442 | }
|
---|
1443 |
|
---|
1444 | return ph2;
|
---|
1445 | }
|
---|
1446 |
|
---|
1447 | // inverse coversine
|
---|
1448 | public Phasor acovers(Phasor ph1){
|
---|
1449 | Phasor ph2 = new Phasor();
|
---|
1450 | if(ph1.phaseInDeg==0.0){
|
---|
1451 | ph2.reset(Fmath.acovers(ph1.magnitude), 0.0D);
|
---|
1452 | }
|
---|
1453 | else{
|
---|
1454 | Complex com = ph1.toRectangular();
|
---|
1455 | com = Complex.acovers(com);
|
---|
1456 | ph2 = Phasor.toPhasor(com);
|
---|
1457 | }
|
---|
1458 |
|
---|
1459 | return ph2;
|
---|
1460 | }
|
---|
1461 |
|
---|
1462 | // inverse haversine
|
---|
1463 | public Phasor ahav(Phasor ph1){
|
---|
1464 | Phasor ph2 = new Phasor();
|
---|
1465 | if(ph1.phaseInDeg==0.0){
|
---|
1466 | ph2.reset(Fmath.ahav(ph1.magnitude), 0.0D);
|
---|
1467 | }
|
---|
1468 | else{
|
---|
1469 | Complex com = ph1.toRectangular();
|
---|
1470 | com = Complex.ahav(com);
|
---|
1471 | ph2 = Phasor.toPhasor(com);
|
---|
1472 | }
|
---|
1473 |
|
---|
1474 | return ph2;
|
---|
1475 | }
|
---|
1476 |
|
---|
1477 | // inverse hyperbolic sine
|
---|
1478 | public Phasor asinh(Phasor ph1){
|
---|
1479 | Phasor ph2 = new Phasor();
|
---|
1480 | if(ph1.phaseInDeg==0.0){
|
---|
1481 | ph2.reset(Fmath.asinh(ph1.magnitude), 0.0D);
|
---|
1482 | }
|
---|
1483 | else{
|
---|
1484 | Complex com = ph1.toRectangular();
|
---|
1485 | com = Complex.asinh(com);
|
---|
1486 | ph2 = Phasor.toPhasor(com);
|
---|
1487 | }
|
---|
1488 |
|
---|
1489 | return ph2;
|
---|
1490 | }
|
---|
1491 |
|
---|
1492 | // inverse hyperbolic cosine
|
---|
1493 | public Phasor acosh(Phasor ph1){
|
---|
1494 | Phasor ph2 = new Phasor();
|
---|
1495 | if(ph1.phaseInDeg==0.0){
|
---|
1496 | ph2.reset(Fmath.acosh(ph1.magnitude), 0.0D);
|
---|
1497 | }
|
---|
1498 | else{
|
---|
1499 | Complex com = ph1.toRectangular();
|
---|
1500 | com = Complex.acosh(com);
|
---|
1501 | ph2 = Phasor.toPhasor(com);
|
---|
1502 | }
|
---|
1503 |
|
---|
1504 | return ph2;
|
---|
1505 | }
|
---|
1506 |
|
---|
1507 | // inverse hyperbolic secant
|
---|
1508 | public Phasor asech(Phasor ph1){
|
---|
1509 | Phasor ph2 = new Phasor();
|
---|
1510 | if(ph1.phaseInDeg==0.0){
|
---|
1511 | ph2.reset(Fmath.asech(ph1.magnitude), 0.0D);
|
---|
1512 | }
|
---|
1513 | else{
|
---|
1514 | Complex com = ph1.toRectangular();
|
---|
1515 | com = Complex.asech(com);
|
---|
1516 | ph2 = Phasor.toPhasor(com);
|
---|
1517 | }
|
---|
1518 |
|
---|
1519 | return ph2;
|
---|
1520 | }
|
---|
1521 |
|
---|
1522 | // inverse hyperbolic cosecant
|
---|
1523 | public Phasor acsch(Phasor ph1){
|
---|
1524 | Phasor ph2 = new Phasor();
|
---|
1525 | if(ph1.phaseInDeg==0.0){
|
---|
1526 | ph2.reset(Fmath.acsch(ph1.magnitude), 0.0D);
|
---|
1527 | }
|
---|
1528 | else{
|
---|
1529 | Complex com = ph1.toRectangular();
|
---|
1530 | com = Complex.acsch(com);
|
---|
1531 | ph2 = Phasor.toPhasor(com);
|
---|
1532 | }
|
---|
1533 |
|
---|
1534 | return ph2;
|
---|
1535 | }
|
---|
1536 |
|
---|
1537 |
|
---|
1538 | // LOGICAL FUNCTIONS
|
---|
1539 | // Returns true if the Phasor has a zero phase, i.e. is a real number
|
---|
1540 | public boolean isReal(){
|
---|
1541 | boolean test = false;
|
---|
1542 | if(Math.abs(this.phaseInDeg)==0.0D)test = true;
|
---|
1543 | return test;
|
---|
1544 | }
|
---|
1545 |
|
---|
1546 | // Returns true if the Phasor has a zero magnitude
|
---|
1547 | // or a phase equal to minus infinity
|
---|
1548 | public boolean isZero(){
|
---|
1549 | boolean test = false;
|
---|
1550 | if(Math.abs(this.magnitude)==0.0D || this.phaseInDeg==Double.NEGATIVE_INFINITY)test = true;
|
---|
1551 | return test;
|
---|
1552 | }
|
---|
1553 |
|
---|
1554 | // Returns true if either the magnitude or the phase of the Phasor
|
---|
1555 | // is equal to plus infinity
|
---|
1556 | public boolean isPlusInfinity(){
|
---|
1557 | boolean test = false;
|
---|
1558 | if(this.magnitude==Double.POSITIVE_INFINITY || this.phaseInDeg==Double.POSITIVE_INFINITY)test = true;
|
---|
1559 | return test;
|
---|
1560 | }
|
---|
1561 |
|
---|
1562 |
|
---|
1563 | // Returns true if the magnitude of the Phasor
|
---|
1564 | // is equal to minus infinity
|
---|
1565 | public boolean isMinusInfinity(){
|
---|
1566 | boolean test = false;
|
---|
1567 | if(this.magnitude==Double.NEGATIVE_INFINITY)test = true;
|
---|
1568 | return test;
|
---|
1569 | }
|
---|
1570 |
|
---|
1571 | // Returns true if the Phasor is NaN (Not a Number)
|
---|
1572 | // i.e. is the result of an uninterpretable mathematical operation
|
---|
1573 | public boolean isNaN(){
|
---|
1574 | boolean test = false;
|
---|
1575 | if(this.magnitude!=this.magnitude || this.phaseInDeg!=this.phaseInDeg)test = true;
|
---|
1576 | return test;
|
---|
1577 | }
|
---|
1578 |
|
---|
1579 | // Returns true if two Phasor are identical
|
---|
1580 | // Follows the Sun Java convention of treating all NaNs as equal
|
---|
1581 | // i.e. does not satisfies the IEEE 754 specification
|
---|
1582 | // but does let hashtables operate properly
|
---|
1583 | public boolean equals(Phasor a){
|
---|
1584 | boolean test = false;
|
---|
1585 | if(this.isNaN() && a.isNaN()){
|
---|
1586 | test=true;
|
---|
1587 | }
|
---|
1588 | else{
|
---|
1589 | if(this.magnitude == a.magnitude && this.phaseInDeg == a.phaseInDeg)test = true;
|
---|
1590 | }
|
---|
1591 | return test;
|
---|
1592 | }
|
---|
1593 |
|
---|
1594 |
|
---|
1595 |
|
---|
1596 | // returns true if the differences between the magnitudes and phases of two Phasors
|
---|
1597 | // are less than fract times the larger magnitude or phase
|
---|
1598 | public boolean equalsWithinLimits(Phasor a, double fract){
|
---|
1599 |
|
---|
1600 | boolean test = false;
|
---|
1601 |
|
---|
1602 | double mt = this.magnitude;
|
---|
1603 | double ma = a.magnitude;
|
---|
1604 | double pt = this.phaseInDeg;
|
---|
1605 | double pa = a.phaseInDeg;
|
---|
1606 | double mdn = 0.0D;
|
---|
1607 | double pdn = 0.0D;
|
---|
1608 | double mtest = 0.0D;
|
---|
1609 | double ptest = 0.0D;
|
---|
1610 |
|
---|
1611 | if(mt==0.0D && pt==0.0D && ma==0.0D && pa==0.0D)test=true;
|
---|
1612 | if(!test){
|
---|
1613 | mdn=Math.abs(mt);
|
---|
1614 | if(Math.abs(ma)>mdn)mdn=Math.abs(ma);
|
---|
1615 | if(mdn==0.0D){
|
---|
1616 | mtest=0.0;
|
---|
1617 | }
|
---|
1618 | else{
|
---|
1619 | mtest=Math.abs(ma-mt)/mdn;
|
---|
1620 | }
|
---|
1621 | pdn=Math.abs(pt);
|
---|
1622 | if(Math.abs(pa)>pdn)pdn=Math.abs(pa);
|
---|
1623 | if(pdn==0.0D){
|
---|
1624 | ptest=0.0;
|
---|
1625 | }
|
---|
1626 | else{
|
---|
1627 | ptest=Math.abs(pa-pt)/pdn;
|
---|
1628 | }
|
---|
1629 | if(mtest<fract && ptest<fract)test=true;
|
---|
1630 | }
|
---|
1631 |
|
---|
1632 | return test;
|
---|
1633 | }
|
---|
1634 |
|
---|
1635 | // SOME USEFUL NUMBERS
|
---|
1636 | // returns the number zero (0) as a Phasor
|
---|
1637 | // zero magnituded and zero phase
|
---|
1638 | public static Phasor zero(){
|
---|
1639 | Phasor ph = new Phasor();
|
---|
1640 | ph.magnitude = 0.0D;
|
---|
1641 | ph.phaseInDeg = 0.0D;
|
---|
1642 | ph.phaseInRad = 0.0D;
|
---|
1643 | ph.rectangular.polar(ph.magnitude, ph.phaseInRad);
|
---|
1644 | return ph;
|
---|
1645 | }
|
---|
1646 |
|
---|
1647 | // returns the number one (+1) as a Phasor
|
---|
1648 | // magnitude = 1, phase = zero
|
---|
1649 | public static Phasor plusOne(){
|
---|
1650 | Phasor ph = new Phasor();
|
---|
1651 | ph.magnitude = 1.0D;
|
---|
1652 | ph.phaseInDeg = 0.0D;
|
---|
1653 | ph.phaseInRad = 0.0D;
|
---|
1654 | ph.rectangular.polar(ph.magnitude, ph.phaseInRad);
|
---|
1655 | return ph;
|
---|
1656 | }
|
---|
1657 |
|
---|
1658 | // returns the number minus one (-1) as a Phasor
|
---|
1659 | // magnitude = -1, phase = zero
|
---|
1660 | public static Phasor minusOne(){
|
---|
1661 | Phasor ph = new Phasor();
|
---|
1662 | ph.magnitude = -1.0D;
|
---|
1663 | ph.phaseInDeg = 0.0D;
|
---|
1664 | ph.phaseInRad = 0.0D;
|
---|
1665 | ph.rectangular.polar(ph.magnitude, ph.phaseInRad);
|
---|
1666 | return ph;
|
---|
1667 | }
|
---|
1668 |
|
---|
1669 | // returns the a phasor of given magnitude with zero phase
|
---|
1670 | // magnitude = -1, phase = zero
|
---|
1671 | public static Phasor magnitudeZeroPhase(double mag){
|
---|
1672 | Phasor ph = new Phasor();
|
---|
1673 | ph.magnitude = mag;
|
---|
1674 | ph.phaseInDeg = 0.0D;
|
---|
1675 | ph.phaseInRad = 0.0D;
|
---|
1676 | ph.rectangular.polar(ph.magnitude, ph.phaseInRad);
|
---|
1677 | return ph;
|
---|
1678 | }
|
---|
1679 |
|
---|
1680 | // infinity
|
---|
1681 | // magnitude = plus infinity, phase = 0
|
---|
1682 | public static Phasor plusInfinity(){
|
---|
1683 | Phasor ph = new Phasor();
|
---|
1684 | ph.magnitude = Double.POSITIVE_INFINITY;
|
---|
1685 | ph.phaseInDeg = 0.0D;
|
---|
1686 | ph.phaseInRad = 0.0D;
|
---|
1687 | ph.rectangular = new Complex(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
|
---|
1688 | return ph;
|
---|
1689 | }
|
---|
1690 |
|
---|
1691 | // -infinity
|
---|
1692 | // magnitude = minus infinity, phase = 0
|
---|
1693 | public static Phasor minusInfinity(){
|
---|
1694 | Phasor ph = new Phasor();
|
---|
1695 | ph.magnitude = Double.NEGATIVE_INFINITY;
|
---|
1696 | ph.phaseInDeg = 0.0D;
|
---|
1697 | ph.phaseInRad = 0.0D;
|
---|
1698 | ph.rectangular = new Complex(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY);
|
---|
1699 | return ph;
|
---|
1700 | }
|
---|
1701 |
|
---|
1702 | // Resistance as a phasor
|
---|
1703 | public static Phasor resistancePhasor(double resistance){
|
---|
1704 | Phasor ph = new Phasor(resistance);
|
---|
1705 | return ph;
|
---|
1706 | }
|
---|
1707 |
|
---|
1708 | // inductance as a phasor
|
---|
1709 | public static Phasor inductancePhasor(double inductance, double frequency){
|
---|
1710 | if(Fmath.isNaN(Phasor.frequency)){
|
---|
1711 | Phasor.frequency = frequency;
|
---|
1712 | Phasor.omega = Phasor.frequency*2.0D*Math.PI;
|
---|
1713 | }
|
---|
1714 | else{
|
---|
1715 | throw new IllegalArgumentException("You have already entered a value for the frequency, " + Phasor.frequency + ", that differs from the one you are now attempting to enter, " + frequency);
|
---|
1716 | }
|
---|
1717 | Complex com = Impedance.inductanceImpedance(inductance, Phasor.omega);
|
---|
1718 | Phasor ph = new Phasor();
|
---|
1719 | return ph.toPhasor(com);
|
---|
1720 | }
|
---|
1721 |
|
---|
1722 | // capacitance as a phasor
|
---|
1723 | public static Phasor capacitancePhasor(double capacitance, double frequency){
|
---|
1724 | if(Fmath.isNaN(Phasor.frequency)){
|
---|
1725 | Phasor.frequency = frequency;
|
---|
1726 | Phasor.omega = Phasor.frequency*2.0D*Math.PI;
|
---|
1727 | }
|
---|
1728 | else{
|
---|
1729 | throw new IllegalArgumentException("You have already entered a value for the frequency, " + Phasor.frequency + ", that differs from the one you are now attempting to enter, " + frequency);
|
---|
1730 | }
|
---|
1731 | Complex com = Impedance.capacitanceImpedance(capacitance, Phasor.omega);
|
---|
1732 | Phasor ph = new Phasor();
|
---|
1733 | return ph.toPhasor(com);
|
---|
1734 | }
|
---|
1735 |
|
---|
1736 | // infinite warburg impedance as a phasor
|
---|
1737 | public static Phasor infiniteWarburgPhasor(double sigma, double frequency){
|
---|
1738 | if(Fmath.isNaN(Phasor.frequency)){
|
---|
1739 | Phasor.frequency = frequency;
|
---|
1740 | Phasor.omega = Phasor.frequency*2.0D*Math.PI;
|
---|
1741 | }
|
---|
1742 | else{
|
---|
1743 | throw new IllegalArgumentException("You have already entered a value for the frequency, " + Phasor.frequency + ", that differs from the one you are now attempting to enter, " + frequency);
|
---|
1744 | }
|
---|
1745 | Complex com = Impedance.infiniteWarburgImpedance(sigma, Phasor.omega);
|
---|
1746 | Phasor ph = new Phasor();
|
---|
1747 | return ph.toPhasor(com);
|
---|
1748 | }
|
---|
1749 |
|
---|
1750 | // finite warburg impedance as a phasor
|
---|
1751 | public static Phasor finiteWarburgPhasor(double sigma, double delta, double frequency){
|
---|
1752 | if(Fmath.isNaN(Phasor.frequency)){
|
---|
1753 | Phasor.frequency = frequency;
|
---|
1754 | Phasor.omega = Phasor.frequency*2.0D*Math.PI;
|
---|
1755 | }
|
---|
1756 | else{
|
---|
1757 | throw new IllegalArgumentException("You have already entered a value for the frequency, " + Phasor.frequency + ", that differs from the one you are now attempting to enter, " + frequency);
|
---|
1758 | }
|
---|
1759 | Complex com = Impedance.finiteWarburgImpedance(sigma, delta, Phasor.omega);
|
---|
1760 | Phasor ph = new Phasor();
|
---|
1761 | return ph.toPhasor(com);
|
---|
1762 | }
|
---|
1763 |
|
---|
1764 | // constant phase elelemnt a phasor
|
---|
1765 | public static Phasor constantPhaseElementPhasor(double sigma, double alpha, double frequency){
|
---|
1766 | if(Fmath.isNaN(Phasor.frequency)){
|
---|
1767 | Phasor.frequency = frequency;
|
---|
1768 | Phasor.omega = Phasor.frequency*2.0D*Math.PI;
|
---|
1769 | }
|
---|
1770 | else{
|
---|
1771 | throw new IllegalArgumentException("You have already entered a value for the frequency, " + Phasor.frequency + ", that differs from the one you are now attempting to enter, " + frequency);
|
---|
1772 | }
|
---|
1773 | Complex com = Impedance.constantPhaseElementImpedance(sigma, alpha, Phasor.omega);
|
---|
1774 | Phasor ph = new Phasor();
|
---|
1775 | return ph.toPhasor(com);
|
---|
1776 | }
|
---|
1777 | } |
---|