Skip to main content
10-Marble
February 16, 2024
Solved

How to exchange rows and column of a matrix in mathcad prime 9

  • February 16, 2024
  • 2 replies
  • 1957 views

Dear Community Members,

 

I've been working on a Mathcad function to exchange rows and columns of a square symmetric matrix, and I would appreciate your feedback on its correctness.

I tried but it gives an error. The png file has the problem and the Mathcad has the solution that I tried.

 

Thanks for the help.

 

AR

Best answer by terryhendicott

Hi,

Showed you a three line version of how to test for symmetry using a truth table also corrected as Luc has suggested.

The swapping of the row and column is left to you.

 

Cheers

Terry

2 replies

23-Emerald IV
February 16, 2024

You are using the and() and or() functions. These functions are meant for image operations, accepting only matrices as their arguments:

LucMeekes_0-1708068343024.png

, not to be used as (the) boolean functions you are using them:

LucMeekes_1-1708068375136.png

For boolean operators, use the AND (˄) and OR (˅) operators from the operators tableau.

 

Success!
Luc

21-Topaz II
February 16, 2024

Hi,

Showed you a three line version of how to test for symmetry using a truth table also corrected as Luc has suggested.

The swapping of the row and column is left to you.

 

Cheers

Terry

25-Diamond I
February 17, 2024

Wouldn't do   if C=C^T ...   do the same job easier?

25-Diamond I
February 17, 2024

Some additional remarks:

  • Statements like this have no effect! The error string is neither returned nor shown
    Werner_E_0-1708179862107.png
  • This statement (apart from using the wrong "and" as Luc already explained) sure is not what the task request and not what you want it to so
    Werner_E_1-1708180038607.png

    In case of a wrong value of e, the "return" statement ends the program immediately and returns the string. But you need to collect ALL possible errors and return them each one in one line. So in case of errors your output could have up to five lines (not square, not symmetric, wrong e, row out of bound, column out of bound). So its necessary to collect all errors in a vector and return it only after the last possible error condition is checked.

    The return in the "else" branch would stop the program as well. So in case of a valid e value you get just the string as the result of your function and not the changed matrix as demanded. There is no need for this "else" anyway because in case of a valid e-value the program simply should do what it was written for - modifying the matrix.
  • Using the row and column selectors which Prime provides can make dealing with whole columns or rows much easier than using loops
    Werner_E_2-1708180721466.png