cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

matrix() function question asking

JC_10409281
5-Regular Member

matrix() function question asking

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.

 

JC_10409281_0-1662653768665.png

JC_10409281_1-1662653830043.png

 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:JC_10409281)

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

Werner_E_0-1662656960082.png

and you can make it self contained by using a local assignment

Werner_E_1-1662657012479.png

To fill a matrix with random integers you may use

Werner_E_2-1662657093048.png

Here are some other examples

Werner_E_4-1662657387486.png

Werner_E_5-1662657679698.png

 

 

 

 

View solution in original post

7 REPLIES 7
Werner_E
25-Diamond I
(To:JC_10409281)

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

Werner_E_0-1662656960082.png

and you can make it self contained by using a local assignment

Werner_E_1-1662657012479.png

To fill a matrix with random integers you may use

Werner_E_2-1662657093048.png

Here are some other examples

Werner_E_4-1662657387486.png

Werner_E_5-1662657679698.png

 

 

 

 

JC_10409281
5-Regular Member
(To:Werner_E)

Hi @Werner_E ,

 

It is more clear now, thanks.

LucMeekes
23-Emerald III
(To:JC_10409281)

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

JC_10409281
5-Regular Member
(To:LucMeekes)

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?

JC_10409281_1-1662686967376.png

 

 

 

Werner_E
25-Diamond I
(To:JC_10409281)

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.

Werner_E_0-1662689682078.png

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.

LucMeekes
23-Emerald III
(To:JC_10409281)

There's no need to create the vectors X and Y in this example:

LucMeekes_0-1662707671753.png

f(i,j) could be simplified to:

f(i,j):=i+j+3

 

Success!
Luc

JC_10409281
5-Regular Member
(To:LucMeekes)

Hi @LucMeekes ,

 

 

Thanks.

 

 

Announcements

Top Tags