Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X
Hello!
Sorry for my english
I just found this "problem"
I think that first "mas" was sorted by first column. But "Mathcad 14" doesn't think so... And we get "mas1"... But again "Mathcad" doesn't think that "mas1" is sorted... and so on...
This little thing brought me a lot of problems...
Can you tell me, is it error of "Mathcad 14"? Or it works as it should? And what should I do?..
Thank!
Sergey
Solved! Go to Solution.
This seems to be a bug.
Mike
Thank, Mike! Happy new year!
I think that it is bug too... I try this function on Mathcad 14 M011, M035, Mathcad 15 - all works the same way...
But what should I do?...
It is not a bug. When you sort by column 0 there are multiple solutions that are equally valid. The starting point is one valid solution, and the ending point is another. This may be considered undesirable behavior, but it's not a bug.
Tom wrote a Csort function that allows you to sort by multiple columns (csort does not preserve the order of previous sorts), but that also does not attempt to preserve the order of columns that are not specified for the sorting. So I modified it (in my opinion, the new version is an improvement over Tom's version, but then I wrote the modification, so I am biased ).
Edit: 11:50 AM Dec 31. I just uploaded a new file with a minor modificaton to the new function.
And what about rsort?
rsort behaves exactly the same as csort, except on the rows rather than the columns.
It is not a bug. When you sort by column 0 there are multiple solutions that are equally valid. The starting point is one valid solution, and the ending point is another. This may be considered undesirable behavior, but it's not a bug.
Oh right, my mistake. Nice function by the way.
Maybe this should be added to the Prime request.
Mike
A word of caution. The routine by Tom, as well as the improvement by Richard, fail if the matrix is large enough and you want to sort successively by enough columns. Demonstration:
Phew, it does.
But When I increase lc to 4 (add an extra column to the matrix):
The maximum difference is 8, not 0.
Row 8130 should follow, not precede rows 8131 and 8132.
QED
Luc
Of course there's a solution. If you are willing to take a little more processing time you can get:
With 10 million matrix elements, no problem sorting on 10 columns.
The routine is recursive:
Success!
Luc
Thanks to all! Happy new year!
Sergey
Yes, there are multiple solutions. But I think that there is only one highest priority solution, when you meet values in sorted matrix in the same order as in unsorted matrix, don't you think so?
In an ideal world, yes. But that's not the way the algorithm used for csort works. The input vector could be checked to see if it is already sorted, but csort does not do that, presumably because of the extra overhead required. A small wrapper program could easily be written in Mathcad to do that though.
Hope to see the response of developers.
The developers never comment on these forums. As far as I know, they don't even read them.
It seems that in the program of c(r)sort function we have not more operator but more or equal operator.
I think so too (don't know enough algorithms, it seems like "bubble sort"...)
I think so too (don't know enough algorithms, it seems like "bubble sort"...)
Bubble sort is a terrible algorithm. The csort function uses the heapsort algorithm (it says so in the help). You can read about it in chapter 8 here:
http://www.nrbook.com/a/bookcpdf.php
Note that the help also says: "The heapsort procedure is not a stable sort, meaning that if you sort values with repeated elements, they appear in an arbitrary order.".
On another note - I was a little surprised to see that Mathcad can sort via text.
Mike
I expect a lot of people would have complained if it couldn't!
Has that always been the case with Mathcad?
I take it Mathcad treats the letters as numbers?
Mike
As far as I can recall it has always worked with strings. The sort is alphabetic, so "a10" comes before "a2".
I understand all about csort and Mathcad))) Thanks to all)))
In my opinion it will be good if developers will add alternate functions (alt_csort and alt_rsort). And those functions will work as I want! 😃 (yes, they will work slowly... but they will work!) Some tasks can't be solved with csort and rsort as they are today...
How do you think? Can we tell about this to developers? How can I do this? 😃
Sergey Pichuzhkin wrote:
Can we tell about this to developers? How can I do this? 😃
The usual way is to write your message using invisible ink on black paper and seal it in a lead bottle floating it down your local river so that they can pick it up on the sea shores off Cambridge Mass. after it has gone around the Atlantic a few times
Well I think that has been the most effective method so far <big wink>
Philip
Bearing in mind, of course, that nothing gets implemented until it has been suggested by at least ten people, ten times each, over a period of at least ten years, we should all get out our black paper and invisible ink and start writing!
The usual way is to write your message using invisible ink...
I know 7 examples when the invisible variable/function/operator name is useful.
Do you know more?
Mathcad allow us to change the multiplication sign. A user may select the one from the following:
2×а 2·а 2 х a 2 а 2а
The multiplication sign is invisible in last two examples that conform to the tradition existing in mathematics do not place a sing between efficients, if the first is a constant and the second is a variable.
Comment
For that reason, a variable name cannot start with digits.
However, blank space between the two values may mean as addition, as multiplication. For example, 2 hours 30 minutes, 1 kilometer 200 metes etc. Here the invisible addition sign stands between the same quantities (time and length), and multiplication sign — between the constants and the units. Fig. 1 shows how to solve it in Mathcad.
Sometimes Mathcad is too pedantic in dimensional quantities. For example, one says that some equipment is situated at a height of twenty meters and another at zero and not specifies the units of that zero (meters, centimeters, feet, or inches etc). Nevertheless, Mathcad always displays the units of the dimensional values even when it is not necessary. In that case, we can hide an excess unit converting it to invisible (Fig. 2).
Mathcad works with decimal, binary, hexadecimal, octal numbers. However, we may need to make Mathcad work with forms more exotic, for example, with Roman numbers. For that, we insert the function with the invisible name that returns a Roman number if its argument is an Arabic and conversely the Arabic number if the argument is Roman (Fig. 3).
Example 4. The sparse matrix
Mathcad has powerful instruments to work with vectors and matrixes (arrays). There is one limitation: these arrays should be completely filled. In practice we sometimes deal with nonrectangular matrixes, for example, with triangular. The matrixes may have more complicated form. Fig. 4 shows how to imitate working with sparse matrix.
Example 5. Invisible matker on the plot:
Example 6. Duoble answer with two units:
Example 7. Endless loop:
Some tasks can't be solved with csort and rsort as they are today..
That is true. So unless you have a great deal of patience and are prepared to wait until the alternative functions are implemented (or the heat death of the universe occurs, which may be sooner), use the functions I posted
As far as I can recall it has always worked with strings. The sort is alphabetic, so "a10" comes before "a2".
Now that has no logic at all.
Mike
I expect a lot of people would have complained if it couldn't!
Complained!!!!!!!!
WE DON'T COMPLANE ON HERE DO WE ??????
Mike