from __future__ import division
from math import sqrt, degrees, atan, pi
# Phase shift
#given data :
F0=25 # in N
m=1
f0=F0/m
K=1*10**3 # in N/m
w0=sqrt(K/m)
b=0.05 # in N-s/m
r=b/(2*m) # in s**-1
A=f0*10**3/sqrt(9*w0**4+(16*r**2*(w0)**2))
print "The amplitude, A = %0.2f mm " %A
p=2*w0
fi=atan(2*r*p/(w0**2-p**2)) # radian
fi = degrees(fi) # degree
print "Phase shift is",round(fi,2),"degree or",round(fi*(pi/180),3),"radian."
#phase shift is converted wrong into radians
from numpy import array
# A/Amax
x1=array([0.99,0.98,0.97]) #
wt=50 #
wo=1 #assume
fo=1 #assume
for x in x1:
a=((fo/((wo**2)*((1-x**2)**2+((1/wt**2)*x**2))**(1/2)))) #
am=fo/((wo**2)*(1/wt**2)**(1/2)) #
z=a/am #
print "For p/wo",x,", value of A/Amax is",round(z,2)
from math import pi, sqrt
# Reactance and impedence
#given data :
n=50 # in cycles
w=2*pi*n # in rad/sec
L=1/pi # in H
XL=w*L
print "The reactance, XL = %0.0f ohm " %XL
R=100 # in ohm
Z=sqrt(R**2+XL**2)
print "The impedence, Z = %0.1f ohm " %Z
from math import sqrt, pi
# Current and Capacity
#given data :
E=110 # in V
R=10 # in ohm
L=1*10**-3 # in H
C=1*10**-6 # in F
n=10000 # in Hz
w=2*pi*n
I=E/sqrt(R**2+((w*L)-(1/(w*C)))**2)
print "The current, I = %0.2f A " %I
L1=1/(w**2*C)
print "The value of capacity, L1 = %0.2e F " %L1
#Capacitance is calculated wrong in the textbook
from math import sqrt
# Resonent frequency and Separation
#given data :
L=1*10**-3 # in H
C=0.1*10**-6 # in F
w0=1/sqrt(L*C)
print "Resonant frequency, w0 = %0.e rad/s " %w0
R=10 # in ohm
w2_w1=R/L
print "The separation = %0.e rad/s " %w2_w1
S=w0/w2_w1
print "The sharpness = %0.f " %S