# Integrating elements from matrix

oI'm kinda new at using Mathematica. What I'm trying to do is create a matrix with elements inside.

Do[x1[i] = 2*i, {i, 0, 2}]

Do[x2[j] = 2*j - 1, {j, 0, 2}]

a = Table[x1[i], {i, 0, 2}]


{0, 2, 4}

b = Table[x2[j], {j, 0, 2}]


{-1, 1, 3}

Then I would like to use these elements as part of an integration

NIntegrate[x1[i] + x2[j], {i, 0, 2}, {j, 0, 2}


However, I'm getting:

"NIntegrate::inumr: The integrand Cos[c x] has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,6}}. >>"

while I'm not getting any results I want to use those results and place them in another matrix.

The reason that I'm doing this is because i have a surface with x and y length and the the surface have nun uniform density as well. as in, in some areas the density will be great and some will be little. i have already calculated the density and placed it into a table, but then i have to correspond each density part to location of the surface. so i can calculate apply force on it and see the effect.

• [...] is for functions, [[...]] is for lists/arrays. Where does the Cos mentioned in the error message coming from? It's not in your code. I'm afraid you will need to read some introductory texts about Mathematica first. – Sjoerd C. de Vries Nov 2 '14 at 19:37
• It's great that you included your code, but please add more description about what you are trying to do. It's hard to understand an algorithm by looking at code which fails to implement it. – Simon Woods Nov 2 '14 at 20:46
• Your code produces the error NIntegrate::inumr: The integrand x1[i]+x2[j] has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,2},{0,2}}. >>, not the message you quote....Perhaps you could use ListInterpolation or Interpolation for your density table, to get a continuous interpolation that you could integrate, etc. – Michael E2 Nov 3 '14 at 3:30

1. You do not have any continuously valued functions. You have simply defined six symbols, x1 through x2. You cannot integrate x1[i] or x2[j] with respect to i or j because these symbols are not functions of i and j -- they are only defined for integer values. Maybe you want these to be functions, in which case you should really only define each x1 and x2 once, using the x1[i_]= construction to make a function.
3. Are you sure you don't want a sum? Changing NIntegrate to Sum works out just fine.