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
vecint[2]={8, 6, 2, 8, 0}, {1, 4, 2, 5, 7}isn't even valid syntax. The extra{ ... }are necessary because it is aListofList. Mathematica doesn't have vectors or matrices as distinct objects, it only has lists. Please read this. – flinty Dec 02 '21 at 14:44params = {{x, 0, 1}, {y, 2, 3}}; Integrate[Sin[x] Cos[y], Sequence @@ params]will splat those parameters on the end of theIntegrate. DoingIntegratewith variable parameter lists has been asked before so I will vote to close. – flinty Dec 02 '21 at 15:02