0

I have the following:

 ClearAll["Global`*"]
 n= 3;
 T = Transpose[Table[{t^i}, {i, 0, n}]];
 B = DiagonalMatrix[Range[n], 1, n + 1];
 Print[ T, B]

I want to have a loop for different values of n say n=1 to 100, so I can get T and B.

user62716
  • 731
  • 4
  • 11
  • 2
    Why don't you just create functions? T[n_Integer] := {Array[t^#&, n + 1, 0]} and B[n_Integer] := DiagonalMatrix[Range[n], 1, n + 1] then use them in a table like Table[{T[n], B[n]},{n,1,100}] – flinty Jun 29 '21 at 17:54
  • many thank, in fact I have long code depend on n, currently I am running it for each n, I was trying to get loop for n – user62716 Jun 29 '21 at 18:08

1 Answers1

1

Try putting it in another Table:

Table[
 {Transpose[Table[{t^i}, {i, 0, n}]],
  DiagonalMatrix[Range[n], 1, n + 1]},
 {n, 1, 100}]

This will give you a list of pairs {T, B}, and you can specify start and end values for n.

If you don't want a list but just printed expressions, you can use Do and Print:

Do[
 Print[{Transpose[Table[{t^i}, {i, 0, n}]],
   DiagonalMatrix[Range[n], 1, n + 1]}],
 {n, 1, 100}]
VentricleV
  • 96
  • 4