Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added precision argument to print and show functions #148

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jacobhuesman
Copy link

I added a precision argument to print and show to allow for limiting the number of digits displayed by the two functions. Previously for coefficients that didn't come out to be nice numbers, the default number of digits made the output annoying interpret.

Here's an example:

using ControlSystems
A = [-20 -2 0 0; 10 0 -10 0; 0 5 -100 -5; 0 0 4 0]
B = [2 0 0 0]'
C = [0 1 0 0]
D = 0
G = ss(A,B,C,D)

Outputting the transfer function to the terminal looked like this:

# Input
show(zpk(G))

# Output
TransferFunction:
                                 (s + 99.79959839197049)(s + 1.407374883553052e15)(s + 0.20040160804507176)
1.4210854715202004e-14------------------------------------------------------------------------------------------------
                      (s + 99.29631508731481)(s + 1.6701219833671543)(s + 18.905983873522935)(s + 0.12757905579519613)

Continuous-time transfer function model

I added some formatting to make the display a little cleaner:

# Input
show(zpk(G))

# Output
TransferFunction:
               (s + 99.7996)(s + 1.40737e+15)(s + 0.200402)
1.42109e-14----------------------------------------------------
           (s + 99.2963)(s + 1.67012)(s + 18.906)(s + 0.127579)

Continuous-time transfer function model

And adjustable:

# Input
show(zpk(G), 2)

# Output
TransferFunction:
         (s + 100)(s + 1.4e+15)(s + 0.2)
1.4e-14-----------------------------------
       (s + 99)(s + 1.7)(s + 19)(s + 0.13)

Continuous-time transfer function model

@mfalt
Copy link
Member

mfalt commented Sep 2, 2018

Thanks for the great work, it looks a lot better.
Unfortunately, we just pulled a set of major changes into the package (this beast #118) so I'll have to take care of the conflicts, probably be rewriting most of it.

One problem is that we switched from our own implementation of polynomials to Polynomials.jl, and partly use that system for printing now.
The new syntax is from Formatting.jl right? How much of a standard is this, are other packages using it?

@jacobhuesman
Copy link
Author

Oh boy haha... I saw that branch when I was starting on this but figured it would be a while before it was ready to be merged in.

I can look into refactoring this later in the week if you think that this functionality is worthwhile to your package. I just picked Formatting.jl since it was readily available.

The show and print syntax isn't standard as far as I know. I was originally going to use keyword arguments like

print(tf(G), precision=2)

but that doesn't work well with the sprint function that you guys were using.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants