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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Returning an array of matrices using a Mathcad program.

MUFASA
6-Contributor

Returning an array of matrices using a Mathcad program.

This problem came up as a part of a recent linear algebra assignment. problem.png

In this case, we only use matrix multiplication and transpose, yet at the same time express a nontrivial control flow. There are 5^4=625 matrices to check, so performance is not a concern; I am focusing on ease of use.

For reference, here is the answer to this problem:

answer.png

I have tried to write a Mathcad Program for this purpose. But the problem is that, neither it is returning the whole array of matrices, nor the one output that it gives is correct. It is returning A instead of P. The image of the Mathcad Program is:

program.png

Please, if anyone can help me in returning an array of matrices that satisfy the given condition, I would be obliged.

ACCEPTED SOLUTION

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

Even no solution contains a zero element, your loops should start from 0 and not from 1.

Note also the by default (you can change that behaviour) arrays are numbered beginning with 0, thats the reason for "i <-- 0". To apply the modulo operation on every element of the matrix T and not on the matrix itself (which makes no sense and results in an error) you have to use vectorization (the arrow over the expression). The temporary matrix T is necessary because we cannot write

Werner_E_1-1610561820937.png

because if we do so, the matrix multiplication would be done element by element and not the correct way. Se the difference here:

Werner_E_2-1610561950094.png

 

So here is one way to find the solutions via brute force:

Werner_E_0-1610561264491.png

P6 file attached

 

View solution in original post

5 REPLIES 5
LucMeekes
23-Emerald III
(To:MUFASA)

 

Hmm,

The one output it gives is for the last matrix P tried. That is:

LucMeekes_0-1610551663642.png

due to the fact that you did not build an escape into your program.

Did you check this:

LucMeekes_0-1610551376020.png

No wonder:

LucMeekes_1-1610551400068.png

Success!
Luc

MUFASA
6-Contributor
(To:LucMeekes)

Thanks, LucMeekes. This problem uses the modulo 5 operations. I know a little bit of Mathcad, but I have checked it in wxMaxima, the answer is right. I don't know how to use those operations in Mathcad.  

 

This is the website that has solved this problem in Maple, Mathematica & wxMaxima. I just wanted to make the Mathcad version of the same problem. Perhaps my question didn't convey the problem correctly. I'm sharing the link to the problem.  

 

You can visit the website and check for yourself. I would be obliged if you please find a solution to this problem using programming in Mathcad.

LucMeekes
23-Emerald III
(To:MUFASA)

As Werner has shown, you have to use the mod function:

LucMeekes_0-1610562941333.png

Success!
Luc

Werner_E
25-Diamond I
(To:MUFASA)

Even no solution contains a zero element, your loops should start from 0 and not from 1.

Note also the by default (you can change that behaviour) arrays are numbered beginning with 0, thats the reason for "i <-- 0". To apply the modulo operation on every element of the matrix T and not on the matrix itself (which makes no sense and results in an error) you have to use vectorization (the arrow over the expression). The temporary matrix T is necessary because we cannot write

Werner_E_1-1610561820937.png

because if we do so, the matrix multiplication would be done element by element and not the correct way. Se the difference here:

Werner_E_2-1610561950094.png

 

So here is one way to find the solutions via brute force:

Werner_E_0-1610561264491.png

P6 file attached

 

MUFASA
6-Contributor
(To:Werner_E)

Thank you very much Werner_E 😀😍 & LucMeekes.

Announcements

Top Tags