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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Vectors and Matrics

ptc-6890310
1-Visitor

Vectors and Matrics

If we have an arbitrary vector (V) like the one shown. Using Mathcad we want to order data from lowest to highest like the one shown on right. How would we do that?

image is attached

8 REPLIES 8

VV.png

(My answer as long as everyone in Europe and America are sleeping)

Thanks for answering, however the main idea is to move down through the array comparing adjacent pairs and swapping the values if they are out of order. can you do it this way?

Zack Alhashim wrote:

Thanks for answering, however the main idea is to move down through the array comparing adjacent pairs and swapping the values if they are out of order. can you do it this way?

Would you like to know how does the built-in function sort work?

Yes, I want the left hand side vector to look like the right hand side by swapping the values if they are out of order.

Valery is giving you the answer to your question; but he's being mysterious as well.

THe built-in function "sort" will do exactly what you're asking for: return the vector in increasing order. The syntax is exactly as Valery showed

sorted := sort(unsorted)

As for why Valery's example works, strings are ASCII code.

Werner_E
25-Diamond I
(To:ptc-6890310)

Zack Alhashim wrote:

Yes, I want the left hand side vector to look like the right hand side by swapping the values if they are out of order.

You already got your solution if you just need to sort a vector.

If this is homework and your task is to provide a program in Mathcad to sort a vector using an algorithm like bubblesort, I suggest you post a Mathcadfile to show what you have done so far and where you got stuck. You don't expect us to do your home work, don't you?

You were already given advice on how to program in Mathcad in this thread http://communities.ptc.com/message/272352#272352

I guess its time to show some effort on your own now.

Werner_E
25-Diamond I
(To:ptc-6890310)

In case you have difficulties finding a decent sorting algorithm to implement (which is very unlikely, I guess), I'd recommend this site: http://www.sorting-algorithms.com/

You can compare different algorithms, watch animations and look at the algorithm's pseudo code.

Find attached an attempt to create that kind of animiation in Mathcad for the bubble sort algorithm.

You may play around with the attached sheet, but the sort routine is protected for obvious reasons.

One KISS-program

Sort.png

PS

We need swap(a, b) function (a procedure) in Mathcad!?

Announcements

Top Tags