Simulink isn't letting me uses the syms command.

11 ビュー (過去 30 日間)
Christopher Shober
Christopher Shober 2022 年 12 月 2 日
回答済み: Vidip Jain 2023 年 3 月 20 日
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);

回答 (1 件)

Vidip Jain
Vidip Jain 2023 年 3 月 20 日
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.

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by