Using symbolic syms inside a Simulink Function — Error: Symbolic not allowed
Show older comments
Hello everyone,
I am working with MATLAB/Simulink and trying to implement a time-varying LQR (TV-LQR).
At each simulation step, I want to:
- Take the desired state x_desired
- Linearize the nonlinear model around this state to compute matrices A and B
- Compute the LQR gain K
- Apply the control lawu=udesired−K(x−xdesired)u = u_{\text{desired}} - K (x - x_{\text{desired}})u=udesired−K(x−xdesired)
The problem is that Simulink gives an error saying that symbolic variables (syms) are not allowed inside a Simulink Function.
How can I linearize my model at each step without using symbolic variables in Simulink?
Is there a recommended way to do numerical linearization at runtime?
Thanks!
Accepted Answer
More Answers (1)
Walter Roberson
on 25 Nov 2025
1 vote
You cannot mix symbolic variables and Control System Toolbox or Simulink Control Design https://www.mathworks.com/help/slcontrol/ug/linearize.html .
I am not aware of anything in the Symbolic Toolbox that would help to linearize models. (Though it is true that you can do some steps using the laplace transform of transform functions.)
In https://www.mathworks.com/matlabcentral/answers/305339-how-to-create-a-transfer-function-with-gain-k#comment_395202 I discussed the closest that you can get to symbolic variables using Simulink models (it is not very close.)
Categories
Find more on State-Space Control Design 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!

