Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
Hi,
I am a little confused about the matrix (m,n,f).
I don't very understand what's the role of f in this function.
I try to use this function to do some tests, but I still don't understand why I will get these results.
I don't define the i, j but the Matcahd can do the calculation.
Can someone use an easy example to explain this function to me, it is hard for me to understand it.
Solved! Go to Solution.
the third argument of "matrix" is the name of a function with two arguments (row and column index) which calculates the element value depending on the two indices. The index starts with zeroand thats independent on how you set the system variable ORIGIN!
In case of your examples the max or min of the index number is chosen as value for the matrix element.
Here is another example
and you can make it self contained by using a local assignment
To fill a matrix with random integers you may use
Here are some other examples
the third argument of "matrix" is the name of a function with two arguments (row and column index) which calculates the element value depending on the two indices. The index starts with zeroand thats independent on how you set the system variable ORIGIN!
In case of your examples the max or min of the index number is chosen as value for the matrix element.
Here is another example
and you can make it self contained by using a local assignment
To fill a matrix with random integers you may use
Here are some other examples
The matrix(r,c,f) function creates a matrix of r rows, c columns where each element of the matrix gets the value computed by the function f, which needs to be a function of 2 parameters. For each element the function f is called with the row and column index numbers of that element. So for the top left element in the matrix, where row and column index are both 0, the element value is f(0,0). In your (first) case the function f is max, so the element value is the maximum of 0 and 0, which is 0.
The element to the right has (also) row index 0, but column index 1, the maximum of which is 1, hence the value 1 there. The element to the right of that has column index number 2, and gets 2.
On de next (lower) row, starting from left, the first element has row index number 1, and column index number 0. The maximum is 1, so the element value becomes 1. (Oh, and the minimum of 0 and 1 is 0, that explains the value 0 in the other matrix, where f is minij
Need I explain more?
Success!
Luc
Hi @LucMeekes
Can I only use max(i,j) or min(i,j) in the matrix() function?
Could you use another example of how to use this function?
May I know why this example can not work?
Concerning other examples you may have a look at my answer above.
When it comes to the problem you show in your picture, I cannot duplicate the error. The result is as expected the vector X increased by 2, the first element in matrix Y.
To find out what the problem on your side actually is, you would have to attach the worksheet.
EDIT: Ah, I see! While its usually better to attach the worksheet in question, the problem you experience comes from writing "f(i,j)" instead of just the function name "f" when you call the function matrix.
There's no need to create the vectors X and Y in this example:
f(i,j) could be simplified to:
f(i,j):=i+j+3
Success!
Luc