Question
I have computed an analytical solution to a problem, using the symbolic math toolbox I can now solve the problem with the following MATLAB function function y = symbolicFunction(x0,x1,x2,x3,x4,x5) syms z y = vpa(root(z^6 - z^4*(- 300*x2*x5 + 450*x2^2 + 450*x5^2) - z^3*(7200*x2*x1 + 4800*x2*x4 - 4800*x5*x1 - 7200*x5*x4) - z^2*(18000*x2*x0 - 18000*x2*x3 - 18000*x5*x0 + 18000*x5*x3 + 50400*x1*x4 + 28800*x1^2 + 28800*x4^2) - z*(144000*x1*x0 - 144000*x1*x3 + 144000*x4*x0 - 144000*x4*x3) + 360000*x0*x3 - 180000*x3^2 - 180000*x0^2, z, 1)); end I want to implement this solution in a simulink model, but I cannot directly add this function in simulink. The most important error states Function 'syms' not supported for code generation. I have tried: Trying to write the analytical solution such that it doesn't require the symbolic toolbox, but I didn't manage to achive this. Compiling the function to C-code, but syms, root(), and vpa() are not supported for code generation. Is there any way to get this function or an equivalent to work in simulink?
Expert Answer
Prashant Kumar
PhD Expert
Answered Aug 26, 2026
I have solved this issue by using coder.extrinsic, in essence I have the following function in simulink
function output = symbolicFunctionSimulink(x0,x1,x2,x3,x4,x5)
coder.extrinsic('symbolicFunction');
output = 0; % initializing output
output = symbolicFunction(x0,x1,x2,x3,x4,x5);
end
and had to alter my symbolicFunction.m such that simulink recognized it to be numeric
function y = symbolicFunction(x0,x1,x2,x3,x4,x5) syms z y = double(vpa(root(z^6 - z^4*(- 300*x2*x5 + 450*x2^2 + 450*x5^2) - z^3*(7200*x2*x1 + 4800*x2*x4 - 4800*x5*x1 - 7200*x5*x4) - z^2*(18000*x2*x0 - 18000*x2*x3 - 18000*x5*x0 + 18000*x5*x3 + 50400*x1*x4 + 28800*x1^2 + 28800*x4^2) - z*(144000*x1*x0 - 144000*x1*x3 + 144000*x4*x0 - 144000*x4*x3) + 360000*x0*x3 - 180000*x3^2 - 180000*x0^2, z, 1))); end
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
Related code generation Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →