简体   繁体   中英

Sum notation in 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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM