implement native @zpk class#31
Conversation
| @@ -1,4 +1,5 @@ | |||
| ## Copyright (C) 2009-2016 Lukas F. Reichlin | |||
| ## Copyright (C) 2026 Mitchell Thompkins | |||
There was a problem hiding this comment.
@ttl-octave I'm not sure how appropriate or necessary it is to add my own name here. I was just trying to follow suit.
There was a problem hiding this comment.
This depends on the amount of changes or extension that you have contributed to the file. Im this case (and maybe in some other of this commit) I think there is too little originality. Moreover, your contribution is recorded in the git history anyways.
There was a problem hiding this comment.
@ttl-octave The formatting here is different than what matlab produces, largely because I think getting their formatting correct is hard and I've included the relevant information someone would want when printing this thing. For example for my 25-pole test system it produces this:
Zero/pole/gain model 'sys':
y1 <- u1:
gain: 1
zeros: (none)
poles:
-0.0251327+25.1327i
-0.0251327+50.2655i
-0.0251327+75.3982i
-0.0251327+100.531i
-0.0251327+125.664i
-0.0251327+150.796i
-0.0251327+175.929i
-0.0251327+201.062i
-0.0251327+226.195i
-0.0251327+251.327i
-0.0251327+276.46i
-0.0251327+301.593i
-0.0251327+326.726i
-0.0251327+351.858i
-0.0251327+376.991i
-0.0251327+402.124i
-0.0251327+427.257i
-0.0251327+452.389i
-0.0251327+477.522i
-0.0251327+502.655i
-0.0251327+527.788i
-0.0251327+552.92i
-0.0251327+578.053i
-0.0251327+603.186i
-0.0251327+628.319i
Where matlab produces:
sys =
1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
(s+(0.02513-25.13i)) (s+(0.02513-50.27i)) (s+(0.02513-75.4i)) (s+(0.02513-100.5i)) (s+(0.02513-125.7i)) (s+(0.02513-150.8i)) (s+(0.02513-175.9i)) (s+(0.02513-201.1i)) (s+
(0.02513-226.2i)) (s+(0.02513-251.3i)) (s+(0.02513-276.5i)) (s+(0.02513-301.6i)) (s+(0.02513-326.7i)) (s+(0.02513-351.9i)) (s+(0.02513-377i)) (s+(0.02513-402.1i))
(s+(0.02513-427.3i)) (s+(0.02513-452.4i)) (s+(0.02513-477.5i)) (s+(0.02513-502.7i)) (s+(0.02513-527.8i)) (s+(0.02513-552.9i)) (s+(0.02513-578.1i)) (s+(0.02513-603.2i))
(s+(0.02513-628.3i))
| tol = sqrt (eps); | ||
| while (any (abs ([p_d; z_d_orig] - w_d) < tol)) | ||
| w_c += 0.1 / tsam; | ||
| w_d = exp (w_c * tsam); |
There was a problem hiding this comment.
@ttl-octave I'm pretty sure that
pkg-control/inst/@tf/__d2c__.m
Line 52 in 037fc5f
wd in the while loop, so I changed it.
There was a problem hiding this comment.
@ttl-octave I applied the same fix from #29; let me know if you think that's incorrect/inappropriate.
There was a problem hiding this comment.
@ttl-octave I applied the same fix from #29; let me know if you think that's incorrect/inappropriate.
|
Impressive. Thank you very much for the contribution. I am going to make a review in the next couple of days. None of the code is based on any other software (see Contribution.md), right? Since this is a quite big extension, could you please change the pull request such that it compares to the dev branch? I have just merged main into dev and I therefore don't expect any problems. |
Thanks! I did read the guidelines and am familiar with GPL licensing in general. I didn't use any code reference other than the implementations already provided in this library (like I said it's largely just mechanical |
| @@ -0,0 +1,100 @@ | |||
| ## Copyright (C) 2026 Mitchell Thompkins | |||
There was a problem hiding this comment.
@ttl-octave one other note here, I took the notice from https://github.com/MitchellThompkins/pkg-control/blob/037fc5f50fb9666518667de018fe84865bbbac29/inst/%40tf/__c2d__.m#L1-L23 but that doesn't actually match https://github.com/gnu-octave/pkg-control/blob/eaba61e11b22de7e9b48871f939423e618d12f0e/CONTRIBUTING.md#license-and-documentation. I'm not sure which style is right. (This applies to both the GPL notice and the textinfo section info.
There was a problem hiding this comment.
Regarding the texinfo section, the help text for internal function __xyz__ does not need to follow the general formatting starting with the @deftypefn statement.
The GPL notice of existing files still contains the hint to the name "LTI Syncope", which was introduced by Lukas Reichlin as far as I know. As this name was and is not used officially for the control package it is not referred to in the example comment in the guidelines for contributing (where I just saw the copy & paste error, "statistics package").
Description
This adds a first-class citizen
zpkclass which is intended to resolve #30.The changes here are largely mechanical routing to move data around in z/p/k form that were already provided that way (as would be the case for a call to
c2dwithmatched, you already have the system poles/zero/gain). The currentzpk()implementation in 037fc5f is a shim that immediately callspoly()and returns atf.With these changes and a slightly modified test script from #30, I get a much improved accuracy from
c2d.Modified test script
Changes
@zpkclass which mirrors the other system representation classes (I largely stole from@tf).@tf. In some cases I think that's fine, in others it is probably less appropriate but I would consider that future work (basically audit them and make sure that for each shim it's doing the most numerically correct thing).c2dagainst)@zpk/__d2c__that controls wherewdwas computed and compared in a while loop. As it was written it always compared against a stalewd.__d2c__path here because that patch only fixed the__c2d__path.TODOsfrom@tfand uses matched-z discretization on tf when passed a tf system. The matched-z is properly applied to the zpk system as well.vimfiles