Week 6
Solving Bugs …. Hello everyone, hope this blog finds you well.
Last week, I raised a series of issues and presented them to the SymPy community for review. This week, my task is to engage in discussions during our weekly meetings to address these issues collaboratively. Additionally, I will work on creating and submitting pull requests to resolve the identified problems.
Aim :
My purpose this week was to address Issues - #25308 and #25315. Along with that I continued to open issues as a part of my phase 2 work, which involves any potential improvements in the Sympy control module. I could succesfully send in pull requests for both the issues and raised a couple of issues.
These are the pull requests I have opened this week.
- [GSOC 2.1] Handle the division of Transfer Function instances
- [GSOC 2.2] Add method to evaluate system response of Transfer Functions.
These are the issues I have raised this week.
- Use of Minimal Realization
- Printing Improvement: Is it possible to print an expression in specific order of a variable.
Work : Let us go through the Pull Requests in brief.
Division of Transfer Functions
>>> from sympy import * >>> from sympy.physics.control import * >>> s = Symbol('s') >>> G5 = TransferFunction(s + 6, s - 5, s) >>> G6 = TransferFunction(s + 3, s + 1, s) >>> G6/G6 Series(TransferFunction(s + 3, s + 1, s), TransferFunction(s + 1, s + 3, s))
Evaluate Transfer Functions and Transfer Function Matrices at particular freuqencies
>>> from sympy import * >>> from sympy.abc import s, p, a >>> from sympy.physics.control.lti import TransferFunction >>> from sympy import I >>> tf1 = TransferFunction(1, s**2 + 2*s + 1, s) >>> omega = 0.1 >>> tf1.eval_frequency(I*omega) 1/(0.99 + 0.2*I) >>> tf2 = TransferFunction(s**2, a*s + p, s) >>> tf2.eval_frequency(2) 4/(2*a + p) >>> tf2.eval_frequency(I*2) -4/(2*I*a + p)
Work : Let us go through the Issues in brief.
-
Use of Minimal Realization:
Although SymPy hassimplify
method which the user can apply manually. But in some instances, it is expected that the result is in a minimal format. MATLAB internally uses aminreal()
function for this.MATLAB
K = 2; G = tf([1 2],[1 .5 3]) H = feedback(G,K) H s + 2 --------------- s^2 + 2.5 s + 7
Sympy
tf1 = TransferFunction(2, 1, s) tf2 = TransferFunction(s + 2, s**2 + S(1/2)*s + 3, s) pprint(Feedback(tf2, tf1).doit()) 2 (s + 2) ⋅ ⎝s + 0.5⋅s + 3⎠ ───────────────────────────── 2 2 ⎝s + 0.5⋅s + 3⎠ ⋅ ⎝s + 2.5⋅s + 7⎠
Here actually poles of numerator have been added both in the numerator and in the denominator which is not a good practice. It gives inaccurate results for frequency response as the order of the transfer function inputs increase.
-
Printing Improvement:
I would like to add this but I’m not well versed with the printing module.from sympy import * from sympy.physics.control import * s,k,p = symbols('s k p') tf= TransferFunction(s**2 +p**2 + s + 10 ,s + k**3 + p,s) pprint(tf) 2 2 p + s + s + 10 ──────────────── 3 4 k + p + s
Instead I would like to have the expression in descending orders of powers of s (the complex variable of the system).
2 2 s + s + p + 10 ──────────────── 4 3 s + k + p
Future Work :
In the upcoming week, I will be a bit busy with work at my university so I may not be able to give my optimal output. Still, I will try to send in a pull request implementing the gain
and the phase
margins. A challenge which still exists is the completion of the GSOC 1.2 Pull Request regarding the Root Locus plot.