Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
Hello, I need some help solving this problem:
Given matrix A(n,m). find the row with the most negative elements and replace it with the row with the largest element of the matrix.
Thanks!
I am sure people can help but what is your 1st attempt? Posting it could be useful
i tried this sollution but its too long anyone can size it down ? 😄
got the awnser wich is correct but too long or there is another way of doing it?
Your initial post states that the row with the most negative numbers should be REPLACED by the one with the largest number.
But in your example these two rows are just SWITCHED/EXCHANGED. You should clarify what should happen.
You have to clarify what "row with the most negative elements" should mean. Is it the row with the smallest element or is it the row the the smallest number of negative values?
What should be done if no negative numbers occur in the matrix?
Furthermore you will have to explain what should happen if two or more rows contain the very same number of negative numbers (or the same smallest number)! Should all be replaced by the row with the largest number (switching would not be possible in that case).
And what should happen if the largest number of the matrix appears more than once and in different rows? Which row should be switched in or used for replacement?
Additionally you should state which version of Mathcad/Prime you intend to use. From your screenshots it look like you are using SMath Studio instead.
Where does a problem like this show up? Is it homework?
It is kinda homework and its tasks for getting ready for exam wich is algorithm, and yes i was using SMath Studio cuz we at collage use an older version of MathCad and with the new version i have no idea how to work with it.
it should switch given numbers given in the matrix they are from the head there werent like specific numbers to write.
the person below did it right but way much higher level 😅 wich i dont really understand.
is possible to do it like mine? i believe u can do it with 1 or 2 cyckles but cant figure it out how 😅
So I would suggest that your first attempt should be a pair of nested loops (for row and column) to run through the whole matrix and find the position (row number is all thats needed) where the largest and the smallest matrix elements are found.
Initialize two variables maxval and minval both with the first matrix element.
Then in your loop section ask if the current matrix element is larger than maxval and if thats the case, set maxval to this value and store the row number in a variable maxrow (corresponding to Lucs Xr variable). Similar with the min value.
Now you know the two row numbers and the next step is to exchange these two rows.
Luc did this by using the row selector and an intermediate variable S. If this is not available you may transpose the matrix and use the column selector or do it by another loop element by element.
You know that you can swap to elements A and B by using a temp variable? temp:=A A:=B B:=temp
If you are using old (real) Mathcad (version 15 or below) in college, feel free to attach your attempts done in this version here.
I know it would be too much to ask but would i possible if u did it so i could see using "if" and "else"?😅
I kinda understand what u mean but in visual would be easier 😅
Thank you for helping tho! 🙂
@BB_10497234 wrote:
I know it would be too much to ask but would i possible if u did it so i could see using "if" and "else"?😅
r and c are the variables used in the aforementioned loops which run along the rows and columns.
or even better because more versatile concerning the matrix size
Give it a try!
You post this in a Mathcad forum, although it looks like you're using Smath studio...
Anyway, A Mathcad Prime program to do what you want is:
A Prime 8 file is attached.
Success!
Luc
Thank you u did it what was written but way to advanced is it possible maybe to do with if's/else 😄 i believe u can just do with 1 or 2 cykles but i have no idea how.