Hi, I already had similar problems. The system of equation is of order 3 which might be too hard. But there is a linear part and if this is solved first and then plugged into the remaining 2 equations, sympy can manage it.
I documented my attempt here: https://gist.github.com/cknoll/c03dcf8443c0409d37da (Generally, I think sympy.solve could sometimes be a little bit smarter, to use such structural properties.) On 02/23/2016 06:43 AM, Carl Sandrock wrote: > I am attempting to work a problem from a textbook in sympy, but sympy > fails to find a solution which appears valid. For interest, it is the > design of a PID controller using direct synthesis with a second order > plus dead time model. > > The whole problem can be reduced to finding K_C, tau_I and tau_D which > will make > > K_C*(s**2*tau_D*tau_I + s*tau_I + 1)/(s*tau_I) = (s**2*tau_1*tau_2 + > s*tau_1 + s*tau_2 + 1)/(K*s*(-phi + tau_c)) > > > for given tau_1, tau_2, K and phi. > > > I have tried to solve this by matching coefficients: > > > import sympy > > > s, tau_c, tau_1, tau_2, phi, K = sympy.symbols('s, tau_c, tau_1, tau_2, > phi, K') > > target = (s**2*tau_1*tau_2 + s*tau_1 + s*tau_2 + 1)/(K*s*(-phi + tau_c)) > > K_C, tau_I, tau_D = sympy.symbols('K_C, tau_I, tau_D', real=True) > PID = K_C*(1 + 1/(tau_I*s) + tau_D*s) > > eq = (target - PID).together() > eq *= sympy.denom(eq).simplify() > eq = sympy.poly(eq, s) > > sympy.solve(eq.coeffs(), [K_C, tau_I, tau_D]) > > This returns an empty matrix. However, the textbook provides the > following solution: > > booksolution = {K_C: 1/K*(tau_1 + tau_2)/(tau_c - phi), > tau_I: tau_1 + tau_2,a > tau_D: tau_1*tau_2/(tau_1 + tau_2)} > > Which appears to satisfy the equations I'm trying to solve: > > [c.subs(booksolution).simplify() for c in eq.coeffs()] > > returns > > [0, 0, 0] > > Can I massage this into a form which sympy can solve? What am I doing wong? > > -- > You received this message because you are subscribed to the Google > Groups "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to sympy+unsubscr...@googlegroups.com > <mailto:sympy+unsubscr...@googlegroups.com>. > To post to this group, send email to sympy@googlegroups.com > <mailto:sympy@googlegroups.com>. > Visit this group at https://groups.google.com/group/sympy. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/4d922cfe-9f54-4196-b7d8-15abb053e091%40googlegroups.com > <https://groups.google.com/d/msgid/sympy/4d922cfe-9f54-4196-b7d8-15abb053e091%40googlegroups.com?utm_medium=email&utm_source=footer>. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To post to this group, send email to sympy@googlegroups.com. Visit this group at https://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/56CC8A6B.4080107%40gmx.de. For more options, visit https://groups.google.com/d/optout.