0
votes

I am currently in the process of writing a custom function to compute the RREF of a given m x n matrix. Since I am a complete newbie to MATLAB, I thought it would be a good idea to sample the built-in rref() function.

While examining the part of code that found "the value and index of largest element in the remainder" of the leading column, I had that:

 [p,k] = max(abs(A(i:m,j)))

where m is the number of rows of the matrix, and i=j=1.

I understand that max(abs(A(i:m,j))) gives you the value of the largest element in the leading column - a single scalar answer. However, I cannot understand why it manages to assign two values to [p,k], with kbeing the index number for p. could someone please be kind enough to help?

1

1 Answers

0
votes

k is the position in your vector where the maximum value is.

For instance, assume we use the vector [1,2,5,2,1]. There the max value is 5. This value is at the third position in the vector. So [p,k] = max([1,2,5,2,1]);will return p=5 and k=3.

The function will assing values depending on how you call it.

p = max(...

will assign only p

[p,k] = max(...

will assign p and k.