MATLAB: Using ‘solve’ function in Simulink

coder.extrinsicfsolvesimulinksolvesymsuser defined function

I have a very non-linear equation that I need to solve during run-time of a Simulink simulation. I have been using the 'solve' function in normal scripts to solve for this. Unfortunately, I need this to be solved in run-time of the simulation.
I have tried to use an embedded Matlab function with the 'solve' function in the script. The problem is that it doesn't like 'syms' command used in conjunction with the 'solve' command. I have tried using the coder.extrinsic with the parameter, but it gives the error, "Undefined function or variable 'v'…. It doesn't seem to appreciate that I have declared 'v' as a syms in order for v to be solved for in the 'solve' function.
Has anyone successfully got the 'solve' function to work in a user-defined Matlab block in Simulink? I have raised this issue in front of a few dozen students at my University, and am interested in showing them a solution. Thank you!
For your ease, I have attached the simulation I am attempting to run. You can find the specific problematic block in the 'Velocity' block on the 'Top Level' file.

Best Answer

Try Interpreted Matlab function block, formerly called Matlab function .