-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomphasors.sage.py
executable file
·79 lines (61 loc) · 2.05 KB
/
randomphasors.sage.py
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
# -*- coding: utf-8 -*-
from sage.all_cmdline import * # import sage library
_sage_const_2 = Integer(2)
_sage_const_1 = Integer(1)
_sage_const_0 = Integer(0) #!/usr/bin/env sage
from sage.all import *
# Phases
var("alpha,beta,delta,P", domain="real")
assume(P >= _sage_const_0, P <= _sage_const_1)
# Phasor sums
var("phix,phiy,phi", domain="complex")
assume(phi > _sage_const_0)
# Unpolarized:
ux = phix * exp(I * alpha)
uy = phiy * exp(I * alpha)
print(ux * conjugate(ux)).simplify_full()
print(ux * conjugate(uy)).simplify_full()
print(ux.real() * ux.real() + ux.imag() * ux.imag()).simplify_full().expand()
assert ux.real() * uy.real() + ux.imag() * uy.imag() == (ux * conjugate(uy)).real()
assert -ux.real() * uy.imag() + ux.imag() * uy.real() == (ux * conjugate(uy)).imag()
# Elliptical:
phix = phi
phiy = phi
cosbeta = cos(beta)
sinbeta = sin(beta)
# cosbeta = sqrt((1+P)/2)
# sinbeta = sqrt((1-P)/2)
sin2beta = _sage_const_2 * sinbeta * cosbeta
cos2beta = cosbeta**_sage_const_2 - sinbeta**_sage_const_2
ux0 = phix * cosbeta
uy0 = phiy * sinbeta
ux = ux0 * exp(I * alpha)
uy = uy0 * exp(I * delta) * exp(I * alpha)
# print (ux*conjugate(ux)).simplify_full()
# print (ux*conjugate(uy)).simplify_full()
uxr = ux.real()
uyr = uy.real()
A = phi.real()
AA = _sage_const_1 / (A * sin(delta) * cosbeta) ** _sage_const_2
CC = _sage_const_1 / (A * sin(delta) * sinbeta) ** _sage_const_2
BB = (
-_sage_const_2
* cos(delta)
/ (A**_sage_const_2 * sin(delta) ** _sage_const_2 * sinbeta * cosbeta)
)
assert (
AA * uxr**_sage_const_2 + BB * uxr * uyr + CC * uyr**_sage_const_2
== _sage_const_1
)
DD = sqrt((AA - CC) ** _sage_const_2 + BB**_sage_const_2)
semimajor = A * sqrt(
(_sage_const_1 + sqrt(_sage_const_1 - (sin2beta * sin(delta)) ** _sage_const_2))
/ _sage_const_2
)
semiminor = A * sqrt(
(_sage_const_1 - sqrt(_sage_const_1 - (sin2beta * sin(delta)) ** _sage_const_2))
/ _sage_const_2
)
tanchi = (CC - AA - DD) / BB
tan2chi = _sage_const_2 * tanchi / (_sage_const_1 - tanchi**_sage_const_2)
assert tan2chi == sin2beta / cos2beta * cos(delta)