1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ [...] 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. $\endgroup$ – Sjoerd C. de Vries Nov 2 '14 at 19:37
  • $\begingroup$ 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. $\endgroup$ – Simon Woods Nov 2 '14 at 20:46
  • $\begingroup$ 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. $\endgroup$ – Michael E2 Nov 3 '14 at 3:30
4
$\begingroup$

There are a number of things that are going wrong here, and I'm not sure where to start:

  1. You do not have any continuously valued functions. You have simply defined six symbols, x1[0] through x2[2]. 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.

  2. These are not in a matrix. I'm not sure what matrix you are looking for, but there is no matrix here. (Cue silly movie reference about "the red pill").

  3. Are you sure you don't want a sum? Changing NIntegrate to Sum works out just fine.

If this does not help, please add more information to this question so that we know what you are really trying to do here.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.