Skip to content

add/cleanup documentation on simulation functions #905

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

Merged
merged 1 commit into from
Jun 7, 2023

Conversation

murrayrm
Copy link
Member

@murrayrm murrayrm commented Jun 5, 2023

This PR updates the user guide and docstrings to provide more information on simulation functions, addressing issues #890 and #893.

I also added the missing OptimalEstimationProblem and OptimalEstimationResult classes to the documentation.

@coveralls
Copy link

Coverage Status

coverage: 94.623%. remained the same when pulling f0a34df on murrayrm:simdocs-04Jun2023 into 184d83d on python-control:main.

@sawyerbfuller
Copy link
Contributor

Any reason why initial_response, step_response, and forced_response can’t/shouldn’t be modified to be compatible with NonlinearIOSystems? It was a bit confusing to students in my class last quarter why they had to switch to a different simulation function if they included a nonlinear system in their InterconnectedSystem.

As for theimpulse_response of a nonlinear system, I am not sure if there is a general way to handle it.

@murrayrm
Copy link
Member Author

murrayrm commented Jun 5, 2023

It should be possible to make all of the systems work for a NonlinearIOSystem.

For the impulse response, we could take the linearization of the system at the initial condition and then use that to reset the initial condition, though I'd want to think that through make sure that is the right thing to do mathematically.

Copy link
Contributor

@sawyerbfuller sawyerbfuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to add nonlinear system compatibility to time simulation functions to a future PR. LGTM

@frohro
Copy link

frohro commented Jun 7, 2023

@sawyerbfuller,
Here are two comments for your questions.
The terms zero state (forced response) and zero input response (initial condition response) are really only meaningful in a linear system, because, in a linear system, they may be added to get the full response. If the system is nonlinear, then they make no sense. So my advice is do not do anything with them in the non-linear domain.
Likewise, there is no reason to handle an impulse response in a nonlinear way, because its importance comes through superposition, where you can use the impulse response to obtain the total response (the convolution integral). So I don't think you should think about computing it for a nonlinear system. You will just be leading folk astray in their understanding of linear systems.
Rob

@murrayrm murrayrm added this to the 0.9.4 milestone Jun 7, 2023
@sawyerbfuller
Copy link
Contributor

hi @frohro -

These four simulation functions derive their names from the matlab equivalents, initial, impulse, step, and lsim, updated somewhat to have more pythonic or descriptive names, especially for lsim. My sense is that their meaning is widely understood to be what you describe - no input or zero state respectively. Is your sense that they are mis-named in Matlab as well? I don't think I have encountered the precise terminology "zero state" and "zero input", but I see what they mean.

At the very least, there should probably be a warning in initial if the user supplies an input that is ignored.

As for nonlinear simulation, it seems like it would be useful to have functionality available in the library to do the same for nonlinear systems, even if superposition doesn't hold for them. An example that comes to mind is simulating a nonlinear pendulum system from an arbitrary initial state.

Granted, complexities may arise in the extensions of such functions to nonlinear systems because in many cases we will not be able to auto-compute a reasonable time window, but I will assume they can be handled somehow.

@frohro
Copy link

frohro commented Jun 7, 2023

Hi @sawyerbfuller,
My beef is with the naming of these simulation functions. It would be nice if it was as you claim, but it does not match MATLAB.
I'm sorry. I must not have made my point of view clear. Let me try again:

  1. control.forced_response() should be named in a way that it is clear it is a general linear simulation, like MATLAB, which calls it lsim(). The term "forced response" of a linear system is also known as the zero-state response, which means X0 = 0.0, so the initial condition option for the user should not be an option in a function called forced_response! I am unaware of a MATLAB simulation that computes only the forced or zero-state response. Maybe we should call it lsim().
  2. control.input_output_response() already computes the response in a way that works for linear and nonlinear systems. Its name is not quite so poorly chosen, though I would prefer the name to emphasize that it works for both linear and nonlinear systems. In my opinion, we should leave the linear simulation alone, and not add the nonlinear feature to it, because we have a nonlinear one already. It should perhaps be more clear that it is a more general simulation.
  3. control.initial_response() has a parameter, input, which the docs claim is for compatibility with the other simulations, but it is ignored. From my perspective, the confusion of having "input" as a parameter that is ignored is worse than any benefit coming from having the same arguments as other simulations. MATLAB certainly does not do anything like this in its initial function. They have no problem having functions with different arguments if it cuts the confusion. When a casual reader sees a parameter in a function, they will assume it is used in the function. Why would you want two functions to have the same arguments if they perform different tasks, especially when the parameter is ignored in one? Every function would be harder to use, understand, etc.! It just makes the user think you have to take into account an input, even if it is zero in a linear system, and that is false.
    I use the Python control package as a teaching tool. I used to use MATLAB/octave, but I'm switching to Python, and I don't want the control package to give my students the wrong ideas. :-)

I understand that changing function names and parameters are painful, but Python is famous for changing those things, and it can probably be done in a less painful way if careful thought is put into it. Hopefully, it is more clear what bothers me about these things. Thanks for thinking about this.

Rob

@ilayn
Copy link

ilayn commented Jun 7, 2023

Dealing with matlab legacy almost daily on scipy, I think lsim is the worst possible name that they can choose when they were dealing with 8.3 fortran name silliness.

forced response is exactly what is happening. Zero state response has nothing to do with it since initial condition is an impulse response super imposed to the input function. So I don't quite get the argument there. Initial condition is a forcing if you let a mass spring damper system from a nonzero condition. It only hides the fact that somebody/something pumped energy to the system prior to t=0. So in that sense I disagree that initial conditions are independent from the forcing signal that is u. I think this should have been the case for matlab but they did poor naming themselves decades ago.

linear or not input output response tells you that there is this input and and there will be an output. I am not a big fan but any other complexity will make things more magical than what it seems. Again, I don't quite get the distinction between linear and nonlinear it's an operator and if you disagree with that signal processing view than you should have bigger problems that control theory treats systems not this naming.

I believe, somewhat strongly that all this is coming from terrible matlab naming schemes and it's not the fault of python-control. Folks should stop treating matlab as the canon instead and move on.

@frohro
Copy link

frohro commented Jun 7, 2023

@ilayn,
It seems to me that the initial condition can be caused by an impulse or by a lot of other functions driving it before the simulation is started. I like that we have a set of simulations that are strictly linear. The great thing about linear systems is you can use superposition and proportionality. This allows things like convolution, Laplace Transforms, and Fourier series. You can use ideas from linear algebra, which are so helpful in solving real-world problems. The EE students here get several courses in linear systems, Circuit Analysis, Linear Systems Analysis, Signals and Systems, and Linear Algebra just as an undergraduate. If a system isn't linear, we often linearize it to make a solution easier. So I think understanding linear systems is important, and the terms we use to describe them are also important because they help us all communicate better and more easily. I am not pushing this language, because MATLAB does, but because it is the language EE's have been using, at least since I was an undergrad 40 years ago.
Rob

@ilayn
Copy link

ilayn commented Jun 7, 2023

Yes I agree linear systems is the key and they play important role but your argument is basically your last sentence, and if I am understanding correctly, just keep things the same don't change them which I cannot participate in sharing your enthusiasm about it. What is it that goes against the grain here? The initial conditions or matlab incompatibility. Intial conditions are also forcing conditions. So I don't quite understand the argument here.

The matlab syntax is/was clearly wrong for many decades why should we continue that tradition?

@frohro
Copy link

frohro commented Jun 7, 2023

@ilayn, I guess I don't understand why MATLAB was wrong and the present control package is right. Can you help me? Maybe it would help to answer my three points, with proofs or citations why they and MATLAB or wrong? Sorry I'm so dense. :-)

@murrayrm
Copy link
Member Author

murrayrm commented Jun 8, 2023

Just to weigh in a bit:

  • We have a way to handle compatibility with MATLAB: the control.matlab module implements things in the same way as MATLAB for those who prefer that interface (including lsim). If there are places in control.matlab that are not compatible with MATLAB, we should fix those.
  • Some of the problems we are arguing about relate to the history of how these functions came about. In particular, input_output_response was added when we put in nonlinear models and (at that time) state space system were a separate class (now they are effectively a subclass) => we needed both a method for linear systems (forced_response) and nonlinear systems (input_output_response).
  • Related to that, part of the reason that forced_response allows the initial condition to be given is that prior to input_output_response, there was no other function that allowed you to specify both an input function and a non-zero initial condition. I personally agree that lsim is not a great name and that the control module (versus the control.matlab module) should be Pythonic rather that "MATLABic" and the convention we have been using is to write things out (bode_plot, initial_response, etc).

Having said all of that, as we move into 0.10 (see #904), I think we can do the following:

  • Allow initial_response and step_response to work for either linear or nonlinear systems (Add nonlinear system compatibility to time simulation functions #906).
  • Allow forced_response to take a nonzero X0 as an optional argument, but perhaps document it as mainly being there for the "pure" forced response, which at least one textbook defines as corresponding to X0=0 (FBS, page 6-3).
  • Use input_output_response as the general function for simulating a linear or nonlinear system for a specified input and initial condition (suggestions welcome for a better name).
  • Allow impulse_response only for linear systems (mainly because I think it is mainly useful for educational purposes when teaching linear control theory, convolution, etc).

@ilayn
Copy link

ilayn commented Jun 8, 2023

Sorry I'm so dense. :-)

I did not imply anything personal with my remarks, and I don't want the discussion to derail to such direction.

Maybe it would help to answer my three points, with proofs or citations why they and MATLAB or wrong?

If you bother to check matlab's documentation on lsim it accepts both linear and nonlinear models, LPV and identified models of every kind. Thus if we were to be hygenic about linear nonlinear distinction, matlab itself is contradicting its rule. That is what I mean by wrong naming/syntax.

What you probably have in mind for "forced response" is the differential equation solutions; homogeneous solution when you set input term to zero (complementary equation) and non-homogeneous solutions and so on. That is not the right terminology to use if you call nonhomogeneous a forced response. Because like I mentioned, initial conditions are also forcing terms or say inputs happened before t<0. "Forced response" term for zero RHS is a sloppy usage in that respect.

The common terminology for such things are, that I am sure you know vrey well, typically zero-input response (ZIR) (which is called initial in matlab historically) and Zero state response ZSR which initial condition is zero and only input is driving to denote exactly what you are taking as 0.

This in fact opens up for nonlinear systems since we have concepts like zero dynamics and so on.

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