Techniques for making matlabFunction finish executing faster

1 回表示 (過去 30 日間)
Jaskaran Singh Grover
Jaskaran Singh Grover 2020 年 7 月 25 日
回答済み: Pranav Verma 2020 年 8 月 13 日
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})

回答 (1 件)

Pranav Verma
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

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by