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

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

How to form a matrix with variables defined with range?

Cornel
19-Tanzanite

How to form a matrix with variables defined with range?

Hello,

 

Cornel_2-1690896345105.png

Cornel_7-1690896587948.png

 

Cornel_0-1690896207377.png

 

Cornel_1-1690896213742.png

 

I want that x and y to be in a single matrix with 2 columns:

Cornel_5-1690896472250.png

 

Cornel_6-1690896565687.png

 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:LucMeekes)

Nice idea!

Your approach works OK as long as "last" is not actually a member of the result vector

Werner_E_0-1690928776568.png

but it fails if it is

Werner_E_1-1690928817010.png

For the example given it works OK, though,

Werner_E_2-1690928873701.png

but the reason is a round-off error which forces ceil to return the correct number 401

Werner_E_3-1690928921702.png

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 😞

Werner_E_0-1690929745699.png

 

A possible fix might be to to round to something like 7 decimals first and only then apply  floor(...), or trunc(...) .

Werner_E_1-1690930026868.png

 

 

 

 

 

View solution in original post

12 REPLIES 12
ttokoro
20-Turquoise
(To:Cornel)

image.png

Cornel
19-Tanzanite
(To:ttokoro)

Cornel_0-1690897858985.png

Cornel_1-1690897900796.png

 

 

Capture.JPG

LucMeekes
23-Emerald III
(To:Cornel)

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:

LucMeekes_2-1690902271430.png

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

Cornel
19-Tanzanite
(To:ttokoro)

@ttokoro 
I finally figured it out how to do:
Firstly, x and y must be further displayed...

Cornel_0-1690901387486.png

Cornel_1-1690901395524.png

Cornel_2-1690901402193.png

 

 

LucMeekes
23-Emerald III
(To:Cornel)

Note that you are using an undocumented feature, a trick that may at some point (future release of Prime) not work anymore.

 

Success!
Luc

Werner_E
25-Diamond I
(To:Cornel)

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

Werner_E_0-1690915539962.png

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:

Werner_E_1-1690915613031.png

 

Werner_E_2-1690915660837.png

 

LucMeekes
23-Emerald III
(To:Werner_E)

For those interested, the poor man's implementation of mkVec is:

LucMeekes_0-1690921091361.png

gives:

LucMeekes_1-1690921187594.pngLucMeekes_3-1690921239162.png

LucMeekes_2-1690921195191.pngLucMeekes_4-1690921246949.png

LucMeekes_5-1690921280134.png

And if you are fond of making mistakes, you can have it with error checking:

LucMeekes_6-1690922215831.png

 

Success!
Luc

 

 

 

Werner_E
25-Diamond I
(To:LucMeekes)

Nice idea!

Your approach works OK as long as "last" is not actually a member of the result vector

Werner_E_0-1690928776568.png

but it fails if it is

Werner_E_1-1690928817010.png

For the example given it works OK, though,

Werner_E_2-1690928873701.png

but the reason is a round-off error which forces ceil to return the correct number 401

Werner_E_3-1690928921702.png

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 😞

Werner_E_0-1690929745699.png

 

A possible fix might be to to round to something like 7 decimals first and only then apply  floor(...), or trunc(...) .

Werner_E_1-1690930026868.png

 

 

 

 

 

Cornel
19-Tanzanite
(To:Werner_E)


@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.

Werner_E
25-Diamond I
(To:Cornel)

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.

LucMeekes
23-Emerald III
(To:Cornel)

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

Announcements

Top Tags