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

  • Thread starter Thread starter brydustin
  • Start date Start date
  • Tags Tags
    Mathematica
AI Thread Summary
The discussion centers on defining the size of a matrix in Mathematica by creating a zero matrix and modifying it in a loop. The user encounters an error when trying to assign a value to a specific element of the matrix, leading to confusion about the matrix's dimensions. It is suggested to remove the MatrixForm from the initialization line to avoid issues with the assignment. Additionally, the correct syntax for displaying the matrix in MatrixForm is provided. The conversation highlights the importance of understanding how Mathematica handles matrix assignments and formatting.
brydustin
Messages
201
Reaction score
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
You might want to try posting this in the Math forum if you don't get any help here. :smile:
 
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:
comparing a flat solar panel of area 2π r² and a hemisphere of the same area, the hemispherical solar panel would only occupy the area π r² of while the flat panel would occupy an entire 2π r² of land. wouldn't the hemispherical version have the same area of panel exposed to the sun, occupy less land space and can therefore increase the number of panels one land can have fitted? this would increase the power output proportionally as well. when I searched it up I wasn't satisfied with...
Back
Top