Filter löschen
Filter löschen

Simulink isn't letting me uses the syms command.

13 Ansichten (letzte 30 Tage)
Christopher Shober
Christopher Shober am 2 Dez. 2022
Beantwortet: Vidip Jain am 20 Mär. 2023
This is the function block from simulink. I am trying to solve for xr symbolically and then use that value to solve for other values. When I run the script it tells me that "Function 'syms' not supported for code generation.". I tried using the coder.extrinsic command and running it from a .m file, but it wasn't working that way either. Thank you in advance.
function error = errorfcn(Xc,Yc)
syms xr
yr=0.005*xr^2
D1=((((xr-Xc)^2)+(yr-Yc)^2)^.5);
dp2=diff(D1,xr)
xnew=solve(dp2==0,xr)
ynew=0.005*xr^2
D2=((((xnew-Xc)^2)+((ynew-Yc)^2))^.5)
if xnew > xr
error = D2
else
error = -1*D2
end
end
Here is the coder.extrinsic line that I tried running too:
function error = errorfcn(Xc, Yc)
coder.extrinsic(' errorfcn');
error = errorfcn (Xc,Yc);

Antworten (1)

Vidip Jain
Vidip Jain am 20 Mär. 2023
The error message you received indicates that the syms function is not supported for code generation, meaning that it cannot be used to generate C/C++ code from your Simulink model.
One potential solution to this issue is to use the sym function instead of syms to define xr as a symbolic variable. The sym function creates a symbolic variable with a specified name and data type, and can be used for code generation.
Note that the solve function is also not supported for code generation. If you need to solve equations symbolically, you may need to find an alternative approach that is supported for code generation, such as using the fsolve function to numerically solve for the root of an equation.

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by