from sympy import sin, cos, exp, I, symbols, Function from time import time #%% Utility functions class Gamma(Function): # Equation (4) @classmethod def eval(cls, Z): return (Z-Zc)/(Z+Zc) class Z(Function): # Microwave textbook formula @classmethod def eval(cls, Gamma): return Zc*(1+Gamma)/(1-Gamma) class Zatne(Function): # Equation (5) @classmethod def eval(cls, z): return Z(exp(-2j*beta*ell)*Gamma(z)) class stopwatch(object): def __init__(self,name='That'): self.name = name def __enter__(self): self.startTime = time() def __exit__(self,*args): print '{0} took {1:.2f}s'.format(self.name, time()-self.startTime) #%% Definition of the problem space Zc = symbols('Zc', real=True, finite=True, positive=True) Zne,Zfe = symbols('Zne Zfe', finite=True) phi, beta, ell = symbols('phi beta ell', real=True, finite=True, positive=True) #%% Sanity check: utility function unit tests assert Gamma(0) == -1 #assert Gamma(oo) == +1 #TODO: take the limit for oo >> Zc assert Gamma(Zc) == 0 assert Z(0) == Zc assert Z(-1) == 0 #assert Z(1) == oo #TODO: take the limit for oo >> Zc assert Zatne(Zc) == Zc #%% Reduction of the problem space by fixing one or more variables #Zc = 50 Zne = Zc Zfe = Zc #phi = 0 #beta = 1 #ell = 2 #%% Input of Paul's formulation paulD = cos(beta*ell)*(Zne+Zfe) + I*sin(beta*ell)*(Zc+Zne*Zfe/Zc) Vne_final_Paul = -Zne*2*(cos(beta*ell)+I*sin(beta*ell)*Zfe/Zc - exp(-1*I*cos(phi)*beta*ell)) / paulD #%% Input of Op 't Land's formulation Vne = + (exp(I*(-cos(phi)-1)*beta*ell) -1) Vfe = - (exp(I*(-cos(phi)+1)*beta*ell) -1) * exp(-1*I*beta*ell) Zfe_ne = Zatne(Zfe) Vne_final_OptLand = (Vne + Gamma(Zfe)*Vfe*exp(-1*I*beta*ell)) * (1+(Zne-Zc)/Zc*Zfe_ne/(Zfe_ne+Zne)) #%% Attempt to prove their equivalence equivalence = Vne_final_OptLand - Vne_final_Paul # Equation (15) # print equivalence.evalf() #Useful when checking at one point in the problem space with stopwatch('Solution using sympy heuristics'): print equivalence.simplify() # #with stopwatch('Being a bit more specific about the solution strategy'): # print equivalence.expand(complex=True).trigsimp()