from sympy import init_session
init_session()
%matplotlib notebook

"""
Explanation: Excercises Electric Machinery Fundamentals
Chapter 6
Animation: Determining the rotor-slip with  a compass
End of explanation
"""


f=sin(x)*sin(y)
f

"""
Explanation: Look at a superposition of two sinusoidal signals:
End of explanation
"""


from sympy.simplify.fu import *
g=TR8(f)     # TR8 is a trigonometric expression function from Fu paper
Eq(f, g)

"""
Explanation: This product can be rewritten as a sum using trigonometric equalities. SymPy has a special function for those:
End of explanation
"""


s = 0.03        # slip
fs = 50         # stator frequency in Hz
fr = (1-s)*fs   # rotor frequency in Hz
fr

alpha=2*pi*fs*t
beta=2*pi*fr*t

"""
Explanation: Now let us take an example with two different angular frequencies:
End of explanation
"""


# Create the plot of the stator rotation frequency in blue:
p1=plot(sin(alpha), (t, 0, 1), show=False, line_color='b', adaptive=False, nb_of_points=5000)
# Create the plot of the rotor rotation frequency in green:
p2=plot(0.5*sin(beta), (t, 0, 1), show=False, line_color='g', adaptive=False, nb_of_points=5000)
# Create the plot of the combined flux in red:
p3=plot(0.5*f.subs([(x, alpha), (y, beta)]), (t, 0, 1), 
            show=False, line_color='r', adaptive=False, nb_of_points=5000)
# Make the second and third one a part of the first one.
p1.extend(p2)
p1.extend(p3)
# Display the modified plot object.
p1.show()

"""
Explanation: Now plot the product of both frequencies:
End of explanation
"""


