Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sum notation in julia?

Tags:

sum

julia

I was wondering if anyone knew of a julia equivalent function to a sum using sigma. For example if I wanted a sum of this sort (unsure of how to show sigma notation, so here is a picture of what I am looking for):

Both c and x would be matrices that I would define earlier in the code. Does anyone know how to code this in Julia or whether julia has an equivalent function?
I have used sum for more simple vector sums, but I am not sure if that would translate to much larger matrices. Any ideas?

like image 768
Cam Avatar asked Aug 07 '15 17:08

Cam


1 Answers

If you are talking about plain-old-Julia variables

c = rand(5,3)
x = rand(5,3)
@show sum(c.*x)

But if you are referring to JuMP (based on your previous questions), then use sum{}:

using JuMP
m = Model()
@variable(m, 0 <= x[i=1:5,j=1:3] <= 1)
c = rand(5,3)
@constraint(m, sum{c[i,j]*x[i,j],i=1:5,j=1:3} <= 10)
like image 62
IainDunning Avatar answered Oct 09 '22 05:10

IainDunning