Why is "symsum" so slow?
>> syms k
>> x2 = -.5:.5/1000:.5;
>> fun(k) = exp(-((((k-1)*x2).^2)/.01));
>> tic; p = symsum(fun(k),k,-1,1); toc; % almost 5 seconds
>> tic; p = fun(-1)+fun(0)+fun(1); toc; % about 1 second

 採用された回答

MathWorks Support Team
MathWorks Support Team 2024 年 7 月 29 日
編集済み: MathWorks Support Team 2024 年 8 月 29 日

0 投票

"symsum" is the wrong function to use if you want to add up a few terms. It spends time to look for a general formula that is valid for arbitrarily many terms, and then applies that formula to the given number of terms.
"symsum" is much better when there are many terms.
For fewer terms, use the "sum" function:
>> tic; p = sum(subs(fun(k),k,(-1:1)')); toc; % about 1 second
Please run the below command in the command window of installed MATLAB R2019a version to get release specific documentation of using the "sum" function.
>> web(fullfile(docroot, 'symbolic/symbolic-summation.html'))
 Please follow the below link to search for the required information regarding the current release:

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

製品

リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by