Hi (sorry for bad eng.), i have next code

reset()
var('K1, T1, T2')
var('p')
# Transient function W(p)
W = K1 * p / ((T1 * p - 1) * (T2 * p - 1))
# Amplitude-phase-frequency characteristic W(jw)
Wa(omega) = W(p = I * omega)

Re(omega) = Wa(omega).real()
Im(omega) = Wa(omega).imag()

print(Re)


but last string gives loooooong result, because sagemath don't knows that K1, T1, T2 and omega are real, how to "tell" that to sagemath ?

edit retag close merge delete

Sort by » oldest newest most voted

Try using assume (type assume? at the console or look through the Sage documentation):

sage: var('K1, T1, T2, p, omega')
(K1, T1, T2, p, omega)
sage: assume(K1, 'real')
sage: assume(T1, 'real')
sage: assume(T2, 'real')


You can also try simplifying your expression, even without the assumptions on K1, T1, and T2:

sage: W = K1 * p / ((T1 * p - 1) * (T2 * p - 1))
sage: Wa = W(p = I * omega)
sage: Re = Wa.real_part().full_simplify()
sage: Im = Wa.imag_part().full_simplify()
sage:
sage: print(Re)
-(K1*T1*omega^2 + K1*T2*omega^2)/(T1^2*omega^2 +
(T1^2*omega^4 + omega^2)*T2^2 + 1)

more