Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Vectors and Matrics

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-11-2015
10:31 PM

02-11-2015
10:31 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-12-2015
12:47 AM

02-12-2015
12:47 AM

Re: Vectors and Matrics

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-12-2015
01:36 AM

02-12-2015
01:36 AM

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?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-12-2015
02:08 AM

02-12-2015
02:08 AM

Re: Vectors and Matrics

Zack Alhashim wrote:

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-12-2015
02:30 AM

02-12-2015
02:30 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-12-2015
05:56 AM

02-12-2015
05:56 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-12-2015
06:15 AM

02-12-2015
06:15 AM

Re: Vectors and Matrics

Zack Alhashim wrote:

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-12-2015
02:30 PM

02-12-2015
02:30 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

02-13-2015
01:41 AM

02-13-2015
01:41 AM

Re: Vectors and Matrics

One KISS-program

PS

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

Top Tags