#Chapter 3,Example 3.1 Page 104
import math
R1 = 75. #ohms
R2 = 2600. #ohms
C1 = 25. # nF
C2 = 2.5 #nF
alpha = (10.**9./2.)*(1./(R2*C1)+1./(R1*C1)+1./(R1*C2))
beeta = (1./2.)*math.sqrt(4.*alpha**2.-4.*10.**18./(R1*R2*C1*C2))
t1 = (1./(2.*beeta))*math.log((alpha+beeta)/(alpha-beeta))
K = 0.7/(t1*(alpha-beeta))+1.
t2 = K*t1
print'%s %.2f %s' % (" alpha = ",alpha/1000000,"*10^6")
print'%s %.2f %s' % (" beta = ",beeta/1000000,"*10^6")
print'%s %.2f' % (" K = ",K)
print'%s %.2f %s' % (" t1 = ",t1*10.**6.,"micro sec ")
print'%s %.2f %s' % (" t2 = ",t2*10.**6.,"micro sec ")
#Aproximating the circuit and neglecting R2
t1 = 3.*((C1*C2*10.**-18.)/(C1+C2*10.**-9.))*R1
# C1 and C2 are in parallel and R1 and R2 in series
t2 = 0.7*(R1+R2)*(C1+C2)*10.**-9.
print'%s %.2f %s' % (" t1 =",t1*10.**9.*10.**6.,"micro sec ")
print'%s %.1f %s' % (" t2 = ",t2*10.**6.,"micro sec ")
print("On comparison with the values obtained through exact formulate it is found that whereas wave tail time is more or less same, the wave front time as calculated through approximate formula is quite erroneous.")
# Answers may vary due to round off error
#Chapter 3,Example 3.2 Page 106
t1 = 1.2*10.**-6.
C1 = (0.3/12.)*10.**3.
C2 = 0.4
R1 = (C1+C2)*t1/(3.*(C1*C2*10.**-9.))
t2 = 50.*10.**-6.
R1R2 = t2/(0.7*(C1+C2)*10.**-9.)# (R1+R2)
R2 = R1R2-R1
print'%s %d %s' % (" R1 =",R1," ohm \n ")
print'%s %d %s' % (" R2 = ",R2," ohm \n ")
# Alternative method
ab = 0.7*10.**-6./(t2-t1) # alpha-beta
ghama = C1/C2 # large value therefore
R2 = 10.**3./(C1*ab) # mentioned wrong in the text
# alpha = beta and based on the eq: t1 = (2/(2*alpha))log((2*alpha)/(alpha-beta))
alpha = 2.43
beeta = 2.415656
R1 = (10.**3./C1)*((1./(alpha+beeta))+(62.5/(alpha+beeta)))
V0 = 125.*12.
Vmax = V0/(2.*R1*C2*10.**-3.*beeta)
print'%s %.1f %s' % (" ghama = ",ghama," (large value)\n ")
print'%s %d %s' % (" R2 = ",R2," ohm \n Since alpha aprox. equla to beta ")
print'%s %d %s' % (" \n R1 =",R1+100," ohm \n ")
print'%s %d %s' % (" Vmax =",Vmax," kV \n ")
#Answers vary due to round of error
#Chapter 3,Example 3.3 Page 107
import math
R = 1.
C = 15.*10.**-6.
L = 2.*10.**-3.
V = 125. # kV
v = R/2.*math.sqrt(C/L)
powe = -v*math.asin(math.sqrt(1.-v**2.))/math.sqrt(1.-v**2.)
e = math.exp(powe)
Imax = 2.*V*v*e
t1 = math.sqrt(L*C)*math.asin(math.sqrt(1.-v**2.))/math.sqrt(1.-v**2.)
# based on trila and error t2=1275 micro sec
t2 = 1275. # micro sec
RHS = 0.5286*math.sin(t2/173.2)
print'%s %.2f %s' % (" Imax = ",Imax," KA \n ")
print'%s %d %s' % (" t1 =",t1*10**6-4," micro sec \n ")
print'%s %d %s' % (" t2 = ",t2,"micro sec \n ")
print'%s %.3f %s' % (" RHS = ",RHS," \n ")
print'%s %d %s' % ('Therefore,time to 50 percent value is ',t2,'micro sec')