0

What replacement can we use instead of symsum in a CVX code in Matlab? I want to use a double summation without using a loop, and symsum seems to be the only available option.

Oleg
  • 10,406
  • 3
  • 29
  • 57
Amira Akra
  • 163
  • 11
  • Show your code. Or an example of what you mean. Are you summing to to infinity or to a fixed value? I assume that `symsum` returns a numeric result rather than a closed form expression for your summation. – horchler Sep 13 '14 at 12:39

1 Answers1

0

If you are able to vectorize your function, using sum is the fastest possibility:

sum([1:10].^2) %sum all squares from 1 to 10

If this is not possible, combine arrayfun and sum:

f=@(x)(x^2)
sum(arrayfun(f,1:10))%sum all squares from 1 to 10
Daniel
  • 36,610
  • 3
  • 36
  • 69