Understanding size() Function for 2x2 Matrices

In summary, the function size(A,1) and size(A,2) and size(A,32) return the length along the nth dimension of the matrix A, where the first dimension is the number of columns and the second dimension is the number of rows. For a 2x2 matrix, size(A,n)=2 for n=1,2 and size(A,n)=1 for n>2, as the higher dimensions do not have any entries.
  • #1
tgt
522
2
What does the function size(A,1) and size(A,2) and size(A,32) mean for a random (in other words, any) 2 by 2 matrix?
 
Physics news on Phys.org
  • #2
size(A,n) returns the length along the nth dimension of the matrix A.

This means that for a 2x2 matrix (i.e a 2D matrix) for n>2 we have that size(A,n)=1 but for n=1,2 size(A,n)=2 since it is only in the first two dimensions that the matrix has any entries.
 
  • #3
cpt_carrot said:
size(A,n) returns the length along the nth dimension of the matrix A.

This means that for a 2x2 matrix (i.e a 2D matrix) for n>2 we have that size(A,n)=1 but for n=1,2 size(A,n)=2 since it is only in the first two dimensions that the matrix has any entries.

What is the nth dimension of a matrix A? How is dimension defined?

Isn't it the case that the dimension of a 2x2 matrix is 4?

Or are you referring to that dimension 1 of a matrix is the number of rows. 2nd dimension of a matrix is the column size? But what is the 3rd dimension of a matrix?
 
Last edited:
  • #4
In this context, the first "dimension" is the number of columns, and the second "dimension" is the number of rows.

A 2x2 matrix can be thought of as a single entry in a 1-element long list of 2x2 matrices, which is why the higher "dimensions" in MATLAB all have length 1.

- Warren
 
  • #5
chroot said:
In this context, the first "dimension" is the number of columns, and the second "dimension" is the number of rows.

A 2x2 matrix can be thought of as a single entry in a 1-element long list of 2x2 matrices, which is why the higher "dimensions" in MATLAB all have length 1.

- Warren

I think it's the opposite after trying it on a 3 by 2 matrix. First dimension is the number of rows and second dimension is the number of columns.

However, it would make more sense if MATLAB gave 0 as the size of the higher dimensions of matrices.
 

1. What is the purpose of the size() function for 2x2 matrices?

The size() function for 2x2 matrices is used to determine the number of rows and columns in the matrix. It is a useful tool for understanding and manipulating the dimensions of a matrix.

2. How do I use the size() function for 2x2 matrices in my code?

To use the size() function for 2x2 matrices, you first need to declare a variable to store the matrix. Then, you can call the size() function on that variable and it will return the number of rows and columns in the matrix as a tuple. For example: mat = [[1, 2], [3, 4]] size = size(mat) will return (2, 2).

3. Can the size() function be used for matrices of different sizes?

Yes, the size() function can be used for matrices of any size, not just 2x2. It will return the number of rows and columns for any given matrix.

4. How can I use the size() function to check if a matrix is 2x2?

The size() function can be used to check if a matrix is 2x2 by comparing the returned tuple to the expected size of a 2x2 matrix, which is (2, 2). If the size() function returns (2, 2), then the matrix is 2x2. Otherwise, it is a different size.

5. Are there any other functions that work similarly to the size() function for 2x2 matrices?

Yes, there are other functions that can be used to determine the size of a matrix, such as ndim(), which returns the number of dimensions of the matrix, and shape(), which returns the shape of the matrix as a tuple. However, the size() function is specifically designed for 2x2 matrices and may be more convenient to use in certain situations.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • Linear and Abstract Algebra
Replies
5
Views
1K
  • Linear and Abstract Algebra
Replies
11
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
Replies
7
Views
829
  • Linear and Abstract Algebra
Replies
3
Views
1K
  • Introductory Physics Homework Help
Replies
2
Views
346
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top