How to get numerical equation for my code?
Show older comments
I have the next matlab's code:
function [Y1] = roots_2021a(q)
syms r
Y=airy(1,-r)-q*airy(-r);
x=0:0.1:20;
y=double(subs(Y,r,x));
d=diff(y>0);
k=num2cell(find(d~=0)+1);
X=double(cellfun(@(z)vpasolve(Y==0,r,x(z)),k));
Y1 = unique(X*exp(1j*pi/3));
end
in matlab code works perfectly, but when i compile it in standaolne app i have the next error:
"syms, subs, vpasolve" are excluded from packaging for the MATLAB Runtime environment according to the MATLAB Compiler license. Either remove the file or function from your code, or use the MATLAB function "isdeployed" to ensure the function is not invoked in the deployed component.
What I did: using matlabFunction, I obtained an expression for y, then substituting q into it, I obtained them numerically. After that I could find points on the X axis where y > 0. But then how to substitute all this into vpasolve and get an expression for it - I don't understand....
code for y expression:
syms r q
Y=airy(1,-r)-q*airy(-r);
x=0:0.1:20;
y=subs(Y,r,x);
f = matlabFunction(y)
but how to get the same for all 'roots_2021a' function?
Accepted Answer
More Answers (1)
Walter Roberson
on 12 Oct 2023
0 votes
Nothing in the symbolic toolbox can be compiled or had code generated for it. Nothing .
You need to use an interactive session to build your formula and use matlabFunction to convert it to a numeric function handle. You can use the 'file' option to write the code as a .m file -- if you do then watch out for the default 'optimize' option being on when 'file' is used, as historically there have been serious bugs in the optimizer, so commonly you want to turn the optimizer off when you use 'file'
Then in the MATLAB code that is to be compiled or had code generated for it, you would call the function that was written to file.
You would not take any result from such a function and use it in vpasolve() -- at least not in the session that is to be compiled. You would instead convert the vpasolve() to fzero() or fsolve() calls for numeric use.
Categories
Find more on MATLAB Compiler 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!