Expand summations with different indexes symbolically

Will MATLAB expand summations with different indexes symbolically like this one?

 Accepted Answer

MATLAB does not offer a ∑ operator.
MATLAB offers sum(), which when applied to numeric values, just adds the values.
If you have the Symbolic Toolbox, then can sum() a symbolic expression that has a symbolic subscript; the result will be expanded if it is simple enough.

11 Comments

So can we expand that by MATLAB or not?
If yes, would you please write a code for the summation in that pic? Just as an example in web, not as a "do it for me" example, because I've seen lots of topics and didn't find anything. Surely Lots of people have this problem.
Do you have the Symbolic toolbox? Because it is a lot easier with the symbolic toolbox. If you do not have the symbolic toolbox then it would need to be constructed as a string that you then turned into an anonymous function to execute.
syms f I J m n
sum((f(I+1)-f(I))*n(I) * sum(m(J), J, I+2, 5), I, 1, 3)
Note: I switched from i and j to I and J to avoid conflicts with the use of i and j as sqrt(-1) . It is allowed to assign other values to i and j, but it is better to get into the habit of not using them except when you mean the imaginary unit; otherwise you will tend to slip up accidentally try to index something at complex i, or be left wondering why your solution is not complex like you expected.
Thanks for your time. Unfortunately I don't have Symbolic Toolbox.
When I past your code to MATLAB it says:
>> syms f I J m n
sum((f(I+1)-f(I))*n(I) * sum(m(J), J, I+2, 5), I, 1, 3)
Error using sym/subsindex (line 1558)
Indexing input must be numeric, logical or ':'.
Error in sym>privformat (line 2357)
x = subsindex(x)+1;
Error in sym/subsref (line 1578)
[inds{k},refs{k}] = privformat(inds{k});
Have you tried this code into your own MATLAB? If yes and have the right answer that I shew in that pic, what is my problem? Is it relate to Symbolic Toolbox which not added to my MATLAB and essentially I need to buy Symbolic Toolbox?
You would have received an error about unknown command sym if you did not have the symbolic toolbox.
I have not tried the code as I do not have the symbolic toolbox.
I realized that I used the wrong command for symbolic summation. Try
syms f I J m n
symsum((f(I+1)-f(I))*n(I) * symsum(m(J), J, I+2, 5), I, 1, 3)
Now it says the same previous error:
>> syms f I J m n
symsum((f(I+1)-f(I))*n(I) * symsum(m(J), J, I+2, 5), I, 1, 3)
Error using sym/subsindex (line 1558)
Indexing input must be numeric, logical or ':'.
Error in sym>privformat (line 2357)
x = subsindex(x)+1;
Error in sym/subsref (line 1578)
[inds{k},refs{k}] = privformat(inds{k});
I'm not sure. You could try
evalin(symengine, 'sym((f(I+1)-f(I))*n(I) * sum(m(J), J=I+2..5), I=1..3)')
It seems you're closer to the answer. Now MATLAB says:
>> evalin(symengine, 'sym((f(I+1)-f(I))*n(I) * sum(m(J), J=I+2..5), I=1..3)')
Error using mupadengine/evalin (line 101)
MuPAD error: Error: The left border must not exceed the right border.
[sum]
What do MATLAB means by left or right border?
Sorry, it's pretty late here. I made a typo.
evalin(symengine, 'sum((f(I+1)-f(I))*n(I) * sum(m(J), J=I+2..5), I=1..3)')
The same error
evalin(symengine, 'sum((f(I+1)-f(I))*n(I) * sum(m(J), J=I+2..5), I=1..3)')
Error using mupadengine/evalin (line 101)
MuPAD error: Error: The left border must not exceed the right border.
[sum]
You know I had an equation with 17 3-line sums which each contained 6 sums inside. Indexes included i-8 to i+12.
5 minuets ago I overcame to expand it by my own after a week of typing and doning silly calculations. MATLAB could help me and do it in a second. To me it was more civilized to learn MATLAB in a year then use it to perform my order in a second, but I am an engineer who don't have enough time to learn MATLAB completely.
If MATLAB has written just for scientists so its developers should clarify this has produced JUST for scientists not for ordinary people like me. If they want a more global software they should increase their support and spread the solutions. But every time I ask a question here they delete my question and say you should not ask a "do it for me" question! Even I said in a topic that transfer money to every one who can solve my problem but there was no one to help. Sometimes a good man like you care about people and help'em. God bless you. Thanks for your valuable time broth.
Sorry, I do not have that toolbox to test with. You could try
evalin(symengine, 'sum((f[I_+1]-f[I_])*n[I]*(sum(m[J], J = I_+2 .. 5)), I_ = 1 .. 3)');
MATLAB was not written for scientists. The initial development was done by Dr. Cleve Moler, but it was recognized that it was the Engineers who really liked it and it was developed as a commercial product on that basis. See http://www.mathworks.com/company/newsletters/articles/the-origins-of-matlab.html
MATLAB was not developed with a symbolic system. For a number of years, Mathworks partnered with Maplesoft to use Maple for symbolic computations. For reasons I have not been told, Mathworks purchased SciFace (manufacturers of MuPAD) in 2008, and the next year stopped partnering with Maplesoft, using MuPAD instead. They have improved MuPAD and the interface to the symbolic engine since then, but they are quite distinct products and it is not expected at this time that everything is going to be accessible from the MATLAB level.
Mathworks offers this forum, but it is volunteers who answer the questions here. Sometimes the volunteers work for Mathworks, but it is mostly users helping other users.
One of the activities of the volunteers is to remove duplicate questions such as you had posted. Duplicate questions lead to confusion, and lead to incomplete answers because no-one ever bothers to go and find duplicate questions and post the answer to them. That makes it difficult for other people to search the forum to find questions similar to their own -- and that is one of the most important functions of the Answers forum, to be a place that people can search what has already been done before to find out how to do something. The more time the volunteers have to spend finding and merging or deleting duplicate questions, the less time the volunteers have available to spend answering the questions. The volunteers tend to get a bit grumpy about that.
The volunteers also get grumpy when postings are phrased as orders to do something, rather than as questions.
What makes the volunteers most grumpy is if someone posts that their question is Urgent or an Emergency

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!