- Create your formula in Symbolic Math Toolbox.
- Use matlabFunction to create a MATLAB function that do not depend on Symbolic Math Toolbox anymore.
- Use MATLAB Deployment to reach your goal.
How to use syms inside a function that is called in simulink?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Vinayak Dan
el 27 de Mzo. de 2020
Respondida: Divya Yerraguntla
el 30 de Mzo. de 2020
I have an Extended Kalman Filter in which I have written Matlab functions for jacobians.
I have used syms from symbolic toolbox in order to compute the jacobians. However I get the error message "Function 'syms' not supported for code generation." when I run the Simulink Function.
How do I avoid this error and compute the jacobians ?
The following is my jacobian function which I use in the EKF block.
function Jss = stateTransitionJacobian(X,U)
syms x [3 1];
syms y [3 1];
syms z [4 1];
syms a [3 1];
syms b [3 1];
ge=[0; 0; 9.81];
deltat=0.01;
p=(X(1:3));
v=(X(4:6));
q=(X(7:10));
fm=(U(1:3));
omegam=(U(4:6));
Qplus=[z1 -z2 -z3 -z4; z2 z1 -z4 z3; z3 z4 z1 -z2; z4 -z3 z2 z1];
Qminus=[z1 -z2 -z3 -z4; z2 z1 z4 -z3; z3 -z4 z1 z2; z4 z3 -z2 z1];
I34=[0 1 0 0; 0 0 1 0; 0 0 0 1];
Rq=I34*Qplus*transpose(Qminus)*transpose(I34);
x1=Rq*y;
y1=a-transpose(Rq)*ge;
z1=0.5*Qplus*([b; 0]);
% Xdot=[p1; v1; q1];
Js=jacobian([x; y; z]+[x1; y1; z1]*deltat,[x; y; z]);
Jss=subs(Js,[x; y; z; a; b],[p; v; q; fm; omegam]);
0 comentarios
Respuesta aceptada
Divya Yerraguntla
el 30 de Mzo. de 2020
Hi Vinayak,
As the error describes the syms function is not supported for Code Generation. So a possible workaround in your case would be to use matlabFunction function in order to convert your symbolic expressions to function handle. This eliminates the dependency on Symbolic Math Toolbox and hence facilitates Code Generation.
Workflow to use matlabFunction:
Hope it helps!
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!