Define Size of Matrix Piece by Piece in Loop: Mathematica Help

  • Thread starter brydustin
  • Start date
  • Tags
    Mathematica
In summary, the conversation discusses an attempt to define the size of a matrix by creating a zero matrix and then adding elements to it in a loop. The code involves using a placeholder variable U to represent the matrix, but an error message is received when trying to assign a value to a specific element of U. The person suspects that U may be treated as a tensor, but is unsure why. They also mention checking the dimensions of U, which results in an empty set. Finally, they suggest seeking help in a math forum.
  • #1
brydustin
205
0
Trying to define the size of a matrix by making a zero matrix then adding elements to it (piece by piece in a loop).

Here is the general idea:

U = ConstantArray[0, {3, 3}] // MatrixForm
U[[2, 2]] = 2

(except in the actual code, I would use U[[i,j]] , for example).
My error message is:
Set::noval: Symbol U in part assignment does not have an immediate value. >>

I suspect that it is treating it as a tensor but why? (i.e. U[[2,2]] assigns a value to the second dimension of the tensor, and to the second row (without specifiing column)).
But why? If I check the dimension I get the empty set!
Dimensions
output = {}
what's going on here?
 
Physics news on Phys.org
  • #2
You might want to try posting this in the Math forum if you don't get any help here. :smile:
 
  • #3
brydustin said:
Trying to define the size of a matrix by making a zero matrix then adding elements to it (piece by piece in a loop).

Here is the general idea:

U = ConstantArray[0, {3, 3}] // MatrixForm
U[[2, 2]] = 2

Try just U = ConstantArray[0, {3, 3}] without the //MatrixForm. If you want to view in MatrixForm, say MatrixForm[U = ConstantArray[0, {3, 3}]] or (U = ConstantArray[0, {3, 3}])//MatrixForm

(I don't know why, = precedes // or something)
 
Last edited:

FAQ: Define Size of Matrix Piece by Piece in Loop: Mathematica Help

What is the purpose of defining the size of a matrix piece by piece in a loop?

The purpose of defining the size of a matrix piece by piece in a loop is to break down a larger matrix into smaller, more manageable pieces. This can make it easier to perform calculations or operations on specific parts of the matrix.

How do I define the size of a matrix piece by piece in a loop in Mathematica?

To define the size of a matrix piece by piece in a loop in Mathematica, you can use the functions "Table" and "Part". The "Table" function allows you to create a list of values, and the "Part" function allows you to access specific elements or submatrices within a matrix.

What is the advantage of defining the size of a matrix piece by piece in a loop?

The advantage of defining the size of a matrix piece by piece in a loop is that it allows for more flexibility and control in manipulating specific parts of a matrix. This can be especially useful when dealing with large, complex matrices.

Can the size of a matrix piece be defined differently for each iteration of the loop?

Yes, the size of a matrix piece can be defined differently for each iteration of the loop. This allows for even more customization and control in breaking down a matrix into smaller pieces.

Are there any limitations to defining the size of a matrix piece by piece in a loop?

There are no specific limitations to defining the size of a matrix piece by piece in a loop, but it is important to ensure that the size definitions are accurate and consistent to avoid errors in your calculations or operations.

Similar threads

Replies
5
Views
2K
Replies
18
Views
4K
Replies
1
Views
1K
Replies
6
Views
3K
Replies
3
Views
543
Replies
7
Views
2K
Back
Top