import sympy
tau, zeta, t, w, K = sympy.symbols('tau, zeta, t, w, K', real=True, positive=True)
s = sympy.Symbol('s')
G = K/(tau**2*s**2 + 2*tau*zeta*s + 1)
The impulse response of the second order system is simply the inverse Laplace of G. However, the nature of the inverse depends on the parameter ζ. TAttempting directly to calculate the inverse results in
TypeError: cannot determine truth value of
-zeta/tau - sqrt(zeta + 1)*cos(atan2(0, zeta - 1)/2)*sqrt(Abs(zeta - 1))/tau < oo
There are three cases of interest, ζ>1, ζ=1 and 0<ζ<1
In Sage, I would be able to use assume(zeta > 1) before calculating the inverse to obtain the correct version of the inverse, but I have not found a way to impose such constraints in SymPy. So, first question is whether I can find nice solutions for these cases to the inverse.
Failing that, I want at least to be able to calculate the inverse with known values of all the parameters so that I can animate the response using IPython notebook widgets. Here I have also been out of luck, as some cases result in special values which are not cleanly evaluated to
knownbadvalues = [{K: 5.05, tau: 5., zeta: 1.},
{K: 5.05, tau: 5.05, zeta: 1.05}
]
for values in knownbadvalues:
print sympy.inverse_laplace_transform(G.subs(values), s, t, noconds=True)
(0.202*t - 0.404*EulerGamma - 0.404*polygamma(0, 1.0))*exp(-0.2*t)
0.198019801980198*meijerg(((0.728681938243239, 0.855476477598345), ()), ((), (-0.271318061756761, -0.144523522401655)), exp(t))
ts = numpy.linspace(0, tmax, 100)
sympy.lambdify(t, invL(G.subs(values)), ['numpy', 'sympy'])(ts).n()
fails with "ValueError: sequence too large; must be smaller than 32"Any advice on getting either getting the closed forms or just finding a version which can be evaluated cleanly?
from sympy.assumptions.assume import global_assumptions
global_assumptions.add(Q.positive(zeta - 1))
I am trying to build a workbook to illustrate the effect of various parameters of second order transfer functions. The full workbook is on GitHub, but here is a minimal example of the problem:import sympytau, zeta, t, w, K = sympy.symbols('tau, zeta, t, w, K', real=True, positive=True) s = sympy.Symbol('s')G = K/(tau**2*s**2 + 2*tau*zeta*s + 1)The impulse response of the second order system is simply the inverse Laplace of G. However, the nature of the inverse depends on the parameter ζ. TAttempting directly to calculate the inverse results inTypeError: cannot determine truth value of-zeta/tau - sqrt(zeta + 1)*cos(atan2(0, zeta - 1)/2)*sqrt(Abs(zeta - 1))/tau < oo
There are three cases of interest, ζ>1, ζ=1 and 0<ζ<1In Sage, I would be able to use assume(zeta > 1) before calculating the inverse to obtain the correct version of the inverse, but I have not found a way to impose such constraints in SymPy. So, first question is whether I can find nice solutions for these cases to the inverse.Failing that, I want at least to be able to calculate the inverse with known values of all the parameters so that I can animate the response using IPython notebook widgets. Here I have also been out of luck, as some cases result in special values which are not cleanly evaluated toknownbadvalues = [{K: 5.05, tau: 5., zeta: 1.}, {K: 5.05, tau: 5.05, zeta: 1.05} ]
On Thursday, September 3, 2015 at 7:19:38 PM UTC+3, Carl Sandrock wrote:I am trying to build a workbook to illustrate the effect of various parameters of second order transfer functions. The full workbook is on GitHub, but here is a minimal example of the problem:import sympytau, zeta, t, w, K = sympy.symbols('tau, zeta, t, w, K', real=True, positive=True) s = sympy.Symbol('s')G = K/(tau**2*s**2 + 2*tau*zeta*s + 1)The impulse response of the second order system is simply the inverse Laplace of G. However, the nature of the inverse depends on the parameter ζ. TAttempting directly to calculate the inverse results inTypeError: cannot determine truth value of-zeta/tau - sqrt(zeta + 1)*cos(atan2(0, zeta - 1)/2)*sqrt(Abs(zeta - 1))/tau < oo
This error message does not appear in the current master. However, the result is very complicated and not necessarily correct for all values of the parameters.
There are three cases of interest, ζ>1, ζ=1 and 0<ζ<1In Sage, I would be able to use assume(zeta > 1) before calculating the inverse to obtain the correct version of the inverse, but I have not found a way to impose such constraints in SymPy. So, first question is whether I can find nice solutions for these cases to the inverse.Failing that, I want at least to be able to calculate the inverse with known values of all the parameters so that I can animate the response using IPython notebook widgets. Here I have also been out of luck, as some cases result in special values which are not cleanly evaluated toknownbadvalues = [{K: 5.05, tau: 5., zeta: 1.}, {K: 5.05, tau: 5.05, zeta: 1.05} ]
The results will be better if exact (rational) values are substituted. The integrator can not deal with floats in many cases.