How to use root() and vpa() from symbolic math toolbox in simulink?

Technical Source
2 min readOct 5, 2021

--

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?

ANSWER

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

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

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

No responses yet