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
Nice idea!
Your approach works OK as long as "last" is not actually a member of the result vector
but it fails if it is
For the example given it works OK, though,
but the reason is a round-off error which forces ceil to return the correct number 401
Using floor(...)+1 instead of ceil(...) should fix it (unless we find an example with a numerical inaccuracy in the opposite direction)
EDIT: And the example wasn't hard to find. Both your versions (the orginal with ceil(..) and the suggested fix with floor(..)+1) fail and also my version fails 😞
A possible fix might be to to round to something like 7 decimals first and only then apply floor(...), or trunc(...) .
A range is not an array (neither vector nor matrix). All operations you try to do with them treating a range as an array is dangerous. In contrast to your example, here's what I get with Prime 7:
Instead of a vector of 1x2 matrices, I get a 2x1 matrix with two 6 element vectors.
Now a decent 'flatten' function should be able to transform either result into a 2 column matrix, but never the less, you risk to run into compatibility problems.
The assemble function shows how dangerous it can be (in Prime) to use ranges as arguments to functions.
Success!
Luc
Note that you are using an undocumented feature, a trick that may at some point (future release of Prime) not work anymore.
Success!
Luc
As Luc already noticed, you are using a convenient, but undocumented trick to turn a range into a vector.
Its not really a clever idea in Prime to make vectors and ranges looking the very same.
If you want to be on the save side you may create the necessary vectors using ranges (only used to index the vector elements, like
or you make use of a utility function like the one shown below, which accepts the very same arguments you also provide when defining a range:
For those interested, the poor man's implementation of mkVec is:
gives:
And if you are fond of making mistakes, you can have it with error checking:
Success!
Luc
Nice idea!
Your approach works OK as long as "last" is not actually a member of the result vector
but it fails if it is
For the example given it works OK, though,
but the reason is a round-off error which forces ceil to return the correct number 401
Using floor(...)+1 instead of ceil(...) should fix it (unless we find an example with a numerical inaccuracy in the opposite direction)
EDIT: And the example wasn't hard to find. Both your versions (the orginal with ceil(..) and the suggested fix with floor(..)+1) fail and also my version fails 😞
A possible fix might be to to round to something like 7 decimals first and only then apply floor(...), or trunc(...) .
@Werner_E wrote:
As Luc already noticed, you are using a convenient, but undocumented trick to turn a range into a vector.
"undocumented"
I have a question about the document or the manual description on how to use Mathcad Prime or to see the limitations of Mathcad Prime. Apart from Resources -> Help and Resources -> Community, I did not see other documents in order to describe how to use Mathcad Prime, to see what you can do with Mathcad Prime, what are its limitations, advantages, disadvantages, multiple examples of what you can do and achieve in Mathcad Prime, what are these documented tricks and also undocumented tricks, for better understanding when working with Mathcad. I have not seen any pdf where all this is described, apart, as I said above, Help and Community, which also in the Help the examples and descriptions are quite few of what you can do with Mathcad Prime. Also, other aspects related to any algorithm like how Mathcad Prime calculates in the background, I have not seen.
For example, you cannot see any definition of fourier transform.
I don't know of any comprehensive manual where all features of Prime would be systematically documented and even the implemented algorithms would be set out.
The last comprehensive documentation of Mathcad I am aware of is the printed User Guide of Mathcad 11 which still can be found for download as pdf if you search for it (even here in the forum -> Mathcad 11 Users Guide - PTC Community ).
The printed doc of later Mathcad versions were much thinner, missing the alphabetic function reference section. And as you may know, there is no handbook or the like which wold come with Prime, just a few small pdfs and the HTML help pages.
Many of the numerical algorithms used in old Mathcad are based on the "Numerical Recipes" (-> https://en.wikipedia.org/wiki/Numerical_Recipes) . Some were adopted in Prime, others were replaced by "more modern" algorithms - not always with better success and there is no documentation of them available AFAIK.
Of course undocumented features/tricks like the conversion of a range into a vector by using inline evaluation can't be found in any documentation - otherwise these features could not be called "undocumented".
Undocumented features are found by users usually by chance and may sometimes be kindly made available to us all here in the forum by a posting. There is no collection of such features - at least I am not aware of that somebody may have collected them and made that collection publicly available.
It seems PTC is not very fond of providing paper, or even PDF manuals with Prime.
You may want to have a look at what Brent Maxfield published, both on Mathcad and on Prime.
Success!
Luc