I want to check is some number is larger than the width of a matrix. How do I access one dimension of a matrix variable instead of both dimensions?
dim([A]->L1
L1(1
L1(2
Weird. It told me there was a Data Type error when I tried that earlier. Thanks anyway.
Really? Weird. I wonder if theres a certain way you have to do it. Will have to test
Edit:
As long as you are only retrieving one of the dimensions and not the other:
:dim([A]
:Ans(1
or
:Ans(2
The solution to a complex problem is often a simple answer.
Ok, that seems to work. I must have typed it in wrong earlier.
Is there any way to do it with one line of code though? I tried
dim([A])(1
but it multiplied the matrix by 1 instead of accessing the first element of the dimensions list.
I would like to make sure the program user correctly input a 2x2 matrix using:
If dim([A])≠ {2,2}
however the calculator is giving me a Data Type error ("Wrong value or variable type entered. Ex: Attempted to store a matrix to a list."
Alternatively I could do:
dim([A])->L1
If not(L1(1)=2 and L1(2)=2)
but that seems kind of inelegant.
Instead of storing the dimension to a list, you can use the If() statement for checking the dimension of matrix A like this:
If 4≠sum(dim([A]
This method I mentioned above takes the sum( of the list dimension of [A], it combines the numbers of the list. If 4 is not equal to the sum of {2,2} then the code under the If statement is executed.
Hewwo, my name is Achak Claw. I was formerly BioHazard.
Not really ideal, since the matrix could be of the size 3,1 or 1,3 and pass.
The missing piece is the min( command:
If min(dim([A])={2,2
See, when comparing to lists, you are comparing each element to its counterpart, returning a list of 0's and 1's of the same size as the lists based on whether each pair of elements were equal. Taking the minimum of this list tells you if any of these values are 0, which would imply that at least one pair of elements doesn't match.
The solution to a complex problem is often a simple answer.