0

I have a little manipulation problem. I have the following matrix:

mat = RandomInteger[10, {4, 5}];
mat 
{{8, 6, 2, 8, 0}, {1, 4, 2, 5, 7}, {6, 3, 4, 4, 7}, {6, 4, 7, 9, 9}}

Then I want to store every row sequentially in a vector called vecint like:

vecint[1]={8, 6, 2, 8, 0}
vecint[2]={8, 6, 2, 8, 0}, {1, 4, 2, 5, 7}

I have tried something like the following:

For[i = 1, i < 3, i++, vecint[i] = mat[[1 ;; i, 1 ;; 5]]]

It gives:

vecint[1]={8, 6, 2, 8, 0}
vecint[2]={{8, 6, 2, 8, 0}, {1, 4, 2, 5, 7}}

vecint[1] is correct, but vecint[2] has two curly brackets in excess. There is a way to do this operation?

Thanks for any helps and tips!

You can use Sequence and Evaluate to put in parameter lists into Integrate. For example: params = {{x, 0, 1}, {y, 2, 3}}; Integrate[Sin[x] Cos[y], Sequence @@ params] will splat those parameters on the end of the Integrate

  • 2
    I think you're a bit confused about the brackets. vecint[2]={8, 6, 2, 8, 0}, {1, 4, 2, 5, 7} isn't even valid syntax. The extra { ... } are necessary because it is a List of List. Mathematica doesn't have vectors or matrices as distinct objects, it only has lists. Please read this. – flinty Dec 02 '21 at 14:44
  • I understand what you mean, but i have to use vecint[i] like the parameter of a multiple integration. For example if i can define vecint[2]={x,1,2},{y,2,3} i can write the integration like this: Integrate[x+y,vecint[2]] – Lorenzo Bagnasacco Dec 02 '21 at 14:53
  • It is emerging as an XY problem. Welcome to the Mathematica Stack Exchange. Please edit your post to include a good description of what you want to do. – Syed Dec 02 '21 at 14:58
  • ^^ you should mention this in your question. Please edit it. You can use Sequence and Evaluate to put in parameter lists into Integrate. For example: params = {{x, 0, 1}, {y, 2, 3}}; Integrate[Sin[x] Cos[y], Sequence @@ params] will splat those parameters on the end of the Integrate. Doing Integrate with variable parameter lists has been asked before so I will vote to close. – flinty Dec 02 '21 at 15:02
  • Thanks, I am new here and i don't know how to mention your comment in my question... – Lorenzo Bagnasacco Dec 02 '21 at 15:14
  • @LorenzoBagnasacco use the 'Edit' button. https://imgur.com/a/4riRoNG – flinty Dec 02 '21 at 15:23
  • Now I try to do the same thing below for NIntegrate, but it doesen't work... – Lorenzo Bagnasacco Dec 02 '21 at 16:42

0 Answers0