Filter löschen
Filter löschen

How to tell if c++ S-function is being linearized?

2 Ansichten (letzte 30 Tage)
Seth Hillery
Seth Hillery am 9 Mai 2017
Kommentiert: Alain Kuchta am 16 Mai 2017
Hello,
I have a non-linear c++ s-function in which I need to perform additional calculations to update various parameters that are not persistent during linear analysis runs to obtain an accurate result. This s-function is being linearized by MATLAB's numerical perturbation methods. In the time domain I do not need to perform these calculations again. Is there a flag or parameter somewhere that can be read by an s-function which shows if the current model is being linearized?
Currently I've hobbled together the s-function reading a variable I'm setting in my workspace for linear analysis runs, but this isn't an ideal solution to maintain portability across different applications.
I am running on r2014b.
Thanks, Seth
EDIT: For now I've decided to look through MATLAB's dbstack and look for the 'linearize' function somewhere in that stack. This does not seem ideal but works for the time being.
  3 Kommentare
Seth Hillery
Seth Hillery am 15 Mai 2017
Alain,
The most clear example for my case is the s-function has several output angles which are 'wrapped' values between (-pi, pi]. If I am linearizing very near to the pi/-pi boundary condition the resulting linear solution is incorrect due to the discrete jump in output value when perturbing the system. If I am linearizing I need to 'unwrap' the output such that the result is continuous in this situation producing the correct linearized result, but in the normal simulation run I need the result to be wrapped.
There is one further example which is most likely due to how my code is structured. During the normal simulation I have certain properties which are updated during the derivative function and then retrieved in the output function without re-calculating these properties, which improved run time by a significant amount. In the normal simulation run this seems to have minimal to no impact on the results, but when linearized this creates some inconsistencies, so I have to update these properties on each output calculation when being linearized. I'm not sure the exactly how MATLAB performs the perturbation on the s-function (with respect to order of operations and internal memory states) so it's hard to tell if this is the best solution but the results are correct when re-calculating these properties.
I am familiar with the exact linearization specification option, but unfortunately the exact linearization for my system is not explicitly known. This case is a relatively large system with >100 inputs and >200 states, with the generic capability of supporting N states depending on the required model fidelity. I have external linearization code which I am comparing the MATLAB linearization to for result verification, but this solution is also performing a numerical perturbation to obtain the linearized system, so even if I specified an exact linearization then I would still need to perform a perturbation with the external code for each linear run about the current operating point. Using MATLAB's built-in linearization capability simplifies the process.
Seth
Alain Kuchta
Alain Kuchta am 16 Mai 2017
Hi Seth,
Thanks for providing a detailed description. I think using a block parameter to indicate when the block should behave in normal mode vs. linearization mode is the best solution available. I'm not aware of any way to detect that a block is being executed as part of linearization of a model.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Trimming and Linearization finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by