Cool. That looks useful. If you start using Symbols the results get more
complicated but with this change:
from sympy import symbols
from sympy.matrices import Matrix
from sympy.core.symbol import Symbol
from sympy.polys.polytools import Poly
from sympy.solvers.solvers import solve
def place(A, B, p):
K_symbols = symbols('k0:{0}'.format(A.rows))
K = Matrix([[ k for k in K_symbols]])
closed_coeffs = Matrix((A - B * K).berkowitz()[2])
desired_poly = Poly([1],Symbol('lambda'))
for pole in p:
desired_poly = desired_poly * Poly([1, -pole],Symbol('lambda'))
desired_coeffs = Matrix(desired_poly.all_coeffs())
return K.subs(solve(closed_coeffs - desired_coeffs, K_symbols))
if __name__ == "__main__":
from sympy.abc import a, b, c, d
A = Matrix([[0, 0, a], [a, 0, a], [a, 0, 0]])
B = Matrix([0, 0, a])
p = [b, c, d]
print place(A, B, p)
You get some interesting symbolic functions for the gains:
moorepants@moorepants-UL30A:Desktop$ python pole_placement.py
Matrix([[(a*(a**2 + b*c + b*d + c*d) + b*c*d)/a**3, -b*c*d/a**3, -(b + c +
d)/a]])
The symbolic form, for simple systems, can be very powerful for seeing how
the gains are a function of the system (A, B) and the desired poles.
Jason
moorepants.info
+01 530-601-9791
On Sun, Mar 16, 2014 at 8:32 AM, Maciek Barański <[email protected]>wrote:
> Below is an example of implementation of place command in Matlab (
> http://www.mathworks.com/help/control/ref/place.html;jsessionid=aa5f7955d910961c374bbda6868a
> ).
>
> http://pastie.org/private/woqxo2cqgt8c7qdicyxr9q
>
>
>
>
>
>
> W dniu wtorek, 11 marca 2014 21:54:41 UTC+1 użytkownik Jason Moore napisał:
>>
>> Maciej,
>>
>> Can you provide us with some example SymPy code demonstrating how you
>> want the control tool box to work?
>>
>>
>> Jason
>> moorepants.info
>> +01 530-601-9791
>>
>>
>> On Tue, Mar 11, 2014 at 4:28 PM, Tim Lahey <[email protected]> wrote:
>>
>>> Oh,
>>>
>>> I misread your e-mail. You had the right toolbox, but if you read,
>>> you'll find that it does a lot of symbolic manipulation and derivation. The
>>> toolbox then supports bringing the designed controller into MapleSim.
>>>
>>> Cheers,
>>>
>>> Tim.
>>>
>>> On 2014-03-11, at 4:25 PM, Tim Lahey <[email protected]> wrote:
>>>
>>> >
>>> > That's not the one I was talking about. I'm talking about the Control
>>> Design Toolbox,
>>> >
>>> > http://www.maplesoft.com/products/toolboxes/control_design/
>>> >
>>> > That said, MapleSim is a symbolic tool that uses a numerical back-end
>>> to solve the system of DAEs. MapleSim uses graph theory to derive the set
>>> of equations symbolically. I know because the core of it was developed by
>>> people in my department. I was a system called DynaFlex that they built a
>>> more user-friendly UI and added new capabilities. The original version of
>>> DynaFlex was co-supervised by my PhD supervisor.
>>> >
>>> > Cheers,
>>> >
>>> > Tim.
>>> >
>>> > ---
>>> > Tim Lahey, Ph.D.
>>> > Post-Doctoral Fellow
>>> > Systems Design Engineering
>>> > University of Waterloo
>>> >
>>> > On 2014-03-11, at 4:12 PM, Jason Moore <[email protected]> wrote:
>>> >
>>> >> Looks like a numerical tool "MapleSim": http://www.maplesoft.com/
>>> products/toolboxes/control_design/
>>> >>
>>> >>
>>> >> Jason
>>> >> moorepants.info
>>> >> +01 530-601-9791
>>> >>
>>> >>
>>> >> On Tue, Mar 11, 2014 at 4:10 PM, Tim Lahey <[email protected]> wrote:
>>> >> Maple has a symbolic control toolbox.
>>> >>
>>> >>
>>> >> On 2014-03-11, at 4:08 PM, Jason Moore <[email protected]> wrote:
>>> >>
>>> >>> Maciej,
>>> >>>
>>> >>> Why do you think this is appropriate for a CAS like SymPy? Most
>>> control work is done numerically, probably because most systems are such
>>> high order that symbolics become less useful. Are there even any commercial
>>> examples of symbolic control toolboxes? What is the ultimate utility of
>>> having one?
>>> >>>
>>> >>>
>>> >>> Jason
>>> >>> moorepants.info
>>> >>> +01 530-601-9791
>>> >>>
>>> >>>
>>> >>> On Mon, Mar 10, 2014 at 3:25 PM, Maciek Barański <[email protected]>
>>> wrote:
>>> >>> Hello everyone! I'm Maciej Barański, a student of Automatics and
>>> Robotics from University of Science and Technology in Cracov (AGH).
>>> >>> I'd like to make a functionality for dealing with LTI systems, like
>>> linearization, getting output of the system, checking if the system is
>>> stable, controllable and observable, making feedback control and implement
>>> a linear kalman's filter. Is it a valid idea for GSOC project? I've seen
>>> http://www.mcs.anl.gov/~wozniak/papers/wozniak_mmath.pdf.
>>> >>>
>>> >>> My github account: https://github.com/getrox
>>> >>> My IRC nickname: getrox
>>> >>>
>>> >>> I've made a pull request: https://github.com/sympy/sympy/pull/7254
>>> >>>
>>> >>> Thank you
>>> >>> Maciej
>>> >>>
>>> >>>
>>> >>> --
>>> >>> 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 [email protected].
>>> >>> To post to this group, send email to [email protected].
>>>
>>> >>> Visit this group at http://groups.google.com/group/sympy.
>>> >>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/sympy/34a44d07-2b5e-
>>> 47f0-be21-52b1206dcacd%40googlegroups.com.
>>> >>> 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 [email protected].
>>> >>> To post to this group, send email to [email protected].
>>>
>>> >>> Visit this group at http://groups.google.com/group/sympy.
>>> >>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/sympy/CAP7f1AjpPO%2BzM0%2B-
>>> JWyfRAhodBZn3bhJLFZk6Xj3uKSZV3h45Q%40mail.gmail.com.
>>> >>>
>>> >>> 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 [email protected].
>>> >> To post to this group, send email to [email protected].
>>>
>>> >> Visit this group at http://groups.google.com/group/sympy.
>>> >> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/sympy/A1D8C7CD-C4AA-4CF2-B663-1004422FBB41%40gmail.com.
>>> >>
>>> >> 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 [email protected].
>>> >> To post to this group, send email to [email protected].
>>>
>>> >> Visit this group at http://groups.google.com/group/sympy.
>>> >> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/sympy/CAP7f1AiQPfHDOAZiPXFkUiFrO2YONaZz%3DSSJw8yg8g6WKS0k0Q%
>>> 40mail.gmail.com.
>>> >> 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 [email protected].
>>> To post to this group, send email to [email protected].
>>>
>>> Visit this group at http://groups.google.com/group/sympy.
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/sympy/D0F85117-D303-44AF-B67E-343C1AEB71EE%40gmail.com.
>>> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/0452b0e6-5262-408d-95c4-940ab0b91f10%40googlegroups.com<https://groups.google.com/d/msgid/sympy/0452b0e6-5262-408d-95c4-940ab0b91f10%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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/CAP7f1AhyY2subf9Q2rtgLawz8TxWaRvUMH%3DRN0jzQ%2BW1CzKxdQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.