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

## 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

Tags (2)
8 REPLIES 8

## Re: Vectors and Matrics (My answer as long as everyone in Europe and America are sleeping)

## Re: Vectors and Matrics

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?

## Re: Vectors and Matrics

 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?

## Re: Vectors and Matrics

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.

## Re: Vectors and Matrics

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.

## Re: Vectors and Matrics

 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.

## Re: Vectors and Matrics

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.

## Re: Vectors and Matrics

One KISS-program  PS

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