How do i write the following mathematical equation in MATLAB
4 views (last 30 days)
Show older comments
I have written the following mathematical equation in matlab

as
F = 1/(abs(M)*abs(N))*(sum(sum(abs(SM(i,j)),j,1,abs(N)),i,1,abs(M)));
where F = sigma
I get the following error when i run it.
Error using sum
Too many input arguments.
Error in test_eg2 (line 23)
F = 1/(abs(N)*abs(G))*(sum(sum(abs(Pop(i,j)),j,1,abs(G)),i,1,abs(N)));
Thanks in advance
0 Comments
Answers (2)
Walter Roberson
on 22 Jul 2016
sum() must be given a list of values to total. sum() cannot be passed a variable of summation like you tried to use. sum() is "add these definite and fully pre-computed elements".
You might be tempted to look in the Symbolic Toolbox at symsum() which does accept variables of summation. However, symsum() has the limitation that the variable of summation cannot be used to index a vector or array.
4 Comments
Walter Roberson
on 23 Jul 2016
As I wrote "symsum() has the limitation that the variable of summation cannot be used to index a vector or array"
I am not sure which you are asking about for returning an integer data type. If you are asking about sum() then you can use the 'native' option; see http://www.mathworks.com/help/matlab/ref/sum.html#inputarg_outtype in order for the output to be the same data type as the input.
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!