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

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Problem to solve

BB_10497234
2-Explorer

Problem to solve

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!

10 REPLIES 10
JXBWk
14-Alexandrite
(To:BB_10497234)

I am sure people can help but what is your 1st attempt? Posting it could be useful

BB_10497234
2-Explorer
(To:JXBWk)

BB_10497234_0-1669214192965.png

BB_10497234_1-1669214201388.png

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?

BB_10497234_2-1669214297122.png

 

Werner_E
25-Diamond I
(To:BB_10497234)

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 😅

Werner_E
25-Diamond I
(To:BB_10497234)

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! 🙂

Werner_E
25-Diamond I
(To:BB_10497234)


@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"?😅 


Werner_E_0-1669218707657.png

r and c are the variables used in the aforementioned loops which run along the rows and columns.

Werner_E_1-1669218810353.png

or even better because more versatile concerning the matrix size

Werner_E_2-1669218857731.png

 

Give it a try!

LucMeekes
23-Emerald III
(To:BB_10497234)

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:

LucMeekes_0-1669215660887.png

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.

Announcements

Top Tags