How to use the Jacobian Matrix elements during a Simulink Simulation

12 次查看(过去 30 天)
I would like to do some computations that use the elements of the Jacobian Matrix. Is it possible to use the Jacobian that Simulink is generating (or the one related to the previous iteration) at each time step inside a Matlab Function, for example?
For now I'm working with a simple RLC circuit as initial test (see the attached model). Variables are defined in a callback function, and the same equation is solved using Simulink blocks, Specialized Power Systems and Simscape Electrical.
Thank you in advance for your time and consideration!

回答(1 个)

Aabha
Aabha 2025-2-12
It seems that the functionality of accessing or finding the Jacobian matrix of a Simulink model is not available. However, there are a few possible workarounds that you could try and see if any of those meet your requirements:
  • Write an S-Function in MATLAB that calculates the Jacobian. This usually involves numerical differentiation, where you perturb each state slightly and observe the change in outputs. Integrate this function with Simulink using the “s-function” block, by specifying the name of the MATLAB file corresponding to the S-Function. You can refer to the documentation of the “s-function” for more information: https://www.mathworks.com/help/releases/R2021a/simulink/s-function-basics-matlab.html
  • Use the “jacobian” function of the “Symbolic Math toolbox” by manually coding the equations. To use this toolbox, you can create a separate MATLAB script and generate the Jacobian matrix in using the “jacobian” function. Then, this script can be added to the Simulink model by using the “MATLAB function” block. You can refer to the documentation of the function for more information: https://www.mathworks.com/help/releases/R2021a/symbolic/sym.jacobian.html
It is also possible to get the Solver Jacobian Pattern for a Simulink model. The Solver Profiler supports Jacobian logging and analysis, but only for models that use implicit solvers. You can refer to this link for more details: https://www.mathworks.com/help/releases/R2021a/simulink/slref/exploring-the-solver-jacobian-structure-of-a-model.html
I hope some of these workarounds are helpful to you.

类别

Help CenterFile Exchange 中查找有关 General Applications 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by