Sum of a product to arbitrary precision using MATLAB symbolic toolbox
1 view (last 30 days)
Show older comments
Is it intended behavior that MATLAB Symbolic Toolbox evaluates an expression like
vpa(symsum(symprod(myfactor,'q',1,k),'k',0,3),ndigits)
by evaluating the summand before substituting the index k for 0,1,2, or 3?
The problem I am having is that I am using an expression like the above, and MATLAB is evaluating symprod(myfactor,'q',1,k) as a function of k (which takes around a minute and yields a multi-page expression), and then attempting to evaluate this function at 0, 1, 2, and 3, which is an incredibly complicated thing to do that MATLAB doesn't know how to simplify, when really all it needs to do is evaluate it at 0, 1, 2, and 3 and add those up.
To me this feels like a design flaw (I can't see why you would try to evaluate the summand before replacing the index with an integer), but if it isn't (or if it is), is there any way to write a code that still uses symsum and symprod but causes MATLAB to evaluate the summand at 0, 1, 2, and 3 rather than at general k?
0 Comments
Answers (1)
Walter Roberson
on 20 Jan 2014
symsum() is for symbolic summation. That attempts to find the general formula and only then substitutes in the actual limits. For example symsym(k, k, 0, 3) would calculate k*(k+1)/2 as the general solution and would then substitute in k = 3 to find the answer.
If you are wanting to sum a series of terms, then at the MATLAB level use sum() instead of symsum() -- you can arrayfun() or the like to get the terms to be summed.
At the MuPAD level use _add() (note the underscore). You can also access _add() in MATLAB by using evalin() or feval()
feval(symengine, '_add', symprod(myfactor,'q',1,k), k, 0, 3)
2 Comments
Walter Roberson
on 20 Jan 2014
arrayfun with 'uniform', 0 giving a cell array that can then be added together
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!