Is there a way to calculate jacobians of Simulink models?

6 views (last 30 days)
Hello,
I have a Simulink model of a general ODE of the form
x\dot = f(x,u).
To be able to do sensitivity analysis I would need the gradients of the dynamics with respect to the states df/dx and the inputs df/du along the whole simulated trajectory. As implementing the gradients of the model by hand can be a very daunting task for complex models, I am looking for a method to generate these gradients automatically. I think Simulink is able to calculate the jacobians of the dynamics analytically as they are used in the implicit integrators. Nevertheless, I did not find a way to use these gradients anywhere else. Finite differences or any other numerical methods are no alternative because runtimes are crucial to the application.
For me the ideal solution would be to "parse" the Simulink model once, to generate the analytical gradients of the model, that can afterwards be used to calculate the numerical jacobian in every timestep.
Thank you very much for your help.

Answers (2)

Kaustubha Govind
Kaustubha Govind on 19 Jul 2012
I'm not entirely sure if this is what you're looking for, but it is possible to get the Solver Jacobian Pattern for a Simulink model. Please see Exploring the Solver Jacobian Structure of a Model for more information.

Matthias
Matthias on 19 Jul 2012
Hi Kaustubha,
thanks for your answer. I already read the article you mentioned. Unfortunately it only describes a way of getting the sparsity pattern of the jacobian. I would be very much interested in the whole matrix (ideally in form of some code/equations).
  2 Comments
Kaustubha Govind
Kaustubha Govind on 20 Jul 2012
Matthias: You can convert a sparse matrix to a full matrix using the FULL function. For the example, you simply need to use full(J.Jpattern) to get the full Jacobian matrix.
Matthias
Matthias on 24 Jul 2012
Hi Kaustubha, I see how i can convert the sparse matrix into a full one but nevertheless the matrix I get using J.Jpattern only gives me the sparsity pattern of the gradient. This means I can only see where there are non-zero entries and where not. What I'd like to have is something like the real analytical gradient of the dynamic model.

Sign in to comment.

Categories

Find more on General Applications in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!