Techniques for making matlabFunction finish executing faster
13 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to run the following script where I am finding coefficients of monomials in a degree N polynomial, and trying to save them as a function handle using matlabFunction command. However, this command takes forever to finish, it has been running for a couple days now. Any tips that could make generating this function handle quicker ? like parallel processing, GPUs etc ?
clear all
theta = sym('theta',[4,1],'real');
P = sym('P',[1,5],'real');
Q = sym('Q',[1,5],'real');
R = sym('R',[1,5],'real');
S = sym('S',[1,5],'real');
T = sym('T',[1,5],'real');
U = sym('U',[1,5],'real');
V = sym('V',[1,5],'real');
W = sym('W',[1,5],'real');
theta_tilde = [theta;1];
p = dot(P,theta_tilde)*dot(Q,theta_tilde)*dot(R,theta_tilde)*dot(S,theta_tilde)*dot(T,theta_tilde)*dot(U,theta_tilde)*dot(V,theta_tilde)*dot(W,theta_tilde) ;
[coeff,terms] = coeffs(p,theta);
matlabFunction(coeff, 'File','coeff','Vars', {P,Q,R,S,T,U,V,W})
0 个评论
回答(1 个)
Pranav Verma
2020-8-13
Hi Jaskaran,
The 'File' option optimizes the code and this optimization may be time consuming for some symbolic expressions and functions. You should try the 'Optimize' option to disable this code optimization. You may try to edit your matlabFunction as:
matlabFunction(coeff, 'File','myFile', 'Optimize',false,'Vars', {P,Q,R,S,T,U,V,W})
A small example demostrating the same option is below:
syms x
r = x^2*(x^2 + 1);
f = matlabFunction(r,'File','myfile','Optimize',false);
For further information on matlabFunction, refer to the below documentation link: https://www.mathworks.com/help/symbolic/matlabfunction.html
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!