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

 Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 29 de Jul. de 2024
Editada: MathWorks Support Team el 29 de Ag. de 2024

0 votos

"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:

Más respuestas (0)

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Productos

Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by