How do i write the following mathematical equation in MATLAB

4 visualizaciones (últimos 30 días)
Christy Jackson
Christy Jackson el 22 de Jul. de 2016
Comentada: Thorsten el 25 de Jul. de 2016
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

Respuestas (2)

Walter Roberson
Walter Roberson el 22 de Jul. de 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 comentarios
Walter Roberson
Walter Roberson el 23 de Jul. de 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.
Christy Jackson
Christy Jackson el 25 de Jul. de 2016
I ll try sum() with native option. Thanks

Iniciar sesión para comentar.


Thorsten
Thorsten el 22 de Jul. de 2016
Editada: Thorsten el 22 de Jul. de 2016
If SM is a M * N matrix, you can write
mean2(SM)
or if you don't have the image processing toolbox
mean2(SM(:))

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by