How to deploy when using 'syms' and 'solve' with function input arguments to consist the equation in MATLAB Compiler
42 views (last 30 days)
Show older comments
MathWorks Support Team
on 13 Jun 2023
Answered: MathWorks Support Team
on 13 Jun 2023
Though there is the document "Deploy Generated MATLAB Functions from Symbolic Expressions with MATLAB Compiler", I could not apply to the following code using 'syms' and 'solve' having function input arguments to consist the equation from the Symbolic Math Toolbox.
function sample(a, b, c)
syms x
eqn = a*x^2 + b*x + c == 0;
s = solve(eqn);
y = vpa(s);
disp(y)
end
This is the error message when I just try to use functions from the Symbolic Math Toolbox.
>> ! sample 1 2 3
Unrecognized function or variable 'syms'.
Error in sample (line 2)
'syms' was excluded from packaging for the MATLAB Runtime environment according to the MATLAB Compiler license.
Have the application owner either resolve the file or function from the code, or use the MATLAB function "isdeployed" to ensure the function is not invoked in the deployed component.
Contact the application owner for more details.
Accepted Answer
MathWorks Support Team
on 13 Jun 2023
Here are the steps to deploy your code with both syms and solve when needed the input arguments to make the equation.
1. Generating the anonymous function from the following modified code to set the input argument a, b, c.
syms a b c x
eqn = a*x^2 + b*x + c == 0;
s = solve(eqn)
f = matlabFunction(s)
Then, you can check the anonymous function as below.
f =
function_handle with value:
@(a,b,c)[((b+sqrt(a.*c.*-4.0+b.^2)).*(-1.0./2.0))./a;((b-sqrt(a.*c.*-4.0+b.^2)).*(-1.0./2.0))./a]
2. Use the anonymous function instead of using syms and solve functions.
function sample(a, b, c)
f = @(a,b,c)[((b+sqrt(a.*c.*-4.0+b.^2)).*(-1.0./2.0))./a;((b-sqrt(a.*c.*-4.0+b.^2)).*(-1.0./2.0))./a];
y = f(a,b,c);
disp(y)
end
3. Now, you can run the deployed standalone as below.
>> mcc -m sample.m
>> ! sample 1 2 3
-0.5102 - 0.8835i
-0.5102 + 0.8835i
0 Comments
More Answers (0)
See Also
Categories
Find more on Assumptions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!