How to use symbolic variables and functions (Syms) in a Simulink Matlab Function?

Rakesh · Sep 7, 2021 · 2.6K views
Question
I would like to create a Symbolic function within a Simulink Matlab Function to solve the variables h and t1. Matlab produces error "The function 'syms' is not supported for standalone code generation. See the documentation for coder.extrinsic to learn how you can use this function in simulation." when I try to compile the Simulink Matlab function with the following code.     syms Eq1(h,t1); Eq1(h,t1) = h*t1; I tried adding "coder.extrinsic('syms')" at the top, as shown below, and this generated the error "Undefined function or variable 'h'." coder.extrinsic('syms'); syms Eq1(h,t1); Eq1(h,t1) = h*t1; How do I use symbolic variables and functions (Syms) in a Simulink Matlab Function?
Expert Answer
Profile picture of John Williams
John Williams PhD Expert
Answered Aug 24, 2026
I think the only solution is to use the syms function inside a separate .m file and call that file as extrinsic.
 
Create a new .m file, e.g. solveSyms.m, put all your code there:
 
function out = solveSyms(in)  % add necessary inputs and outputs
  syms x y
  f = x^2*y + 5*x*sqrt(y);  
  out = subs(f, x, in);
end

Now call this new file from the MATLAB Function block:

coder.extrinsic('solveSyms');
out = 0;
out = solveSyms(in);

I'm not very familiar with Symbolic Math toolbox, so you would need to correct the code above to use your equation.

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!