Clear Filters
Clear Filters

How to use symbolic math toolbox to generate the gradient of a very long function?

3 views (last 30 days)
I am currently trying to use fmincon for Nonlinear Model Predictive Control. Typical MPC modeling has its objective function dependent on the length of the horizon, i.e. the number of elements in the optimum solution. My problem is almost same as the closed loop Matlab simulation example given in Swing-up Control of a Pendulum The differences compared to my model are: 1. I am using 4th Runge-Kutta method instead of Euler 2. The expressions used to define the continuous model have other components like tanh function and so on.
I tried to generate gradient and hessian as mentioned in: Symbolic Math Toolbox Example
The problem is that the objective function becomes more and more complex when the length of the optimum solution increases. The expressions become very long and it takes eternally long time to generate those expressions when the length of optimum solution is greater than 4.
I have to generate the expressions for a length of atleast 25. Is there a work around to do this? I understand that longer expressions mean longer time but any tips to make it faster would be appreciated.
Thanks in advance
  3 Comments
Christopher Creutzig
Christopher Creutzig on 3 Dec 2018
It may be worth including your expressions in the question. Or, if you prefer not to make them public, contact support@mathworks.com, so the Symbolic Math team has a chance to look at your problem and either give hints to increase the performance or get feedback about places the toolbox can be improved. Or both.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!