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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Programming and scalar

SS_9781956
8-Gravel

Programming and scalar

I am pretty new to mathcad so working on and learning. Is it possible to get the result from programming in matrix form. I am trying but getting error. Can someone please help

 

Sam

ACCEPTED SOLUTION

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

As Luc already wrote, you have to iterate through your vectors, either by using a range variable, a program with a for-loop or by using vectorization.

Vectorization is quite convenient, but Prime won't allow to vectorize a comparison like AA<10 directly. But you can define a function which compares its argument with a given value and then call that function vectorized with your vector as argument.

Using a function may be convenient if you need the same or a similar comparison of a vector with a value more than once in your sheet. If the value you compare with (10 in your example) changes, you may make it the second argument of your function.
Its a matter of personal taste if you prefer the programmed if-branch or the if-function.

Werner_E_0-1630508930190.png

 

View solution in original post

12 REPLIES 12
Werner_E
25-Diamond I
(To:SS_9781956)

I am pretty sure that its possible to achieve what you have in mind, but to help you it would be necessary to see what you are trying to do.

So if possible you should attach your worksheet so we can have a look at and maybe it also helps if you additionally state which result you are looking for.
If you are using the newest version of Prime, it may also help to attach a picture (if the worksheet is short) for people (like me) not able to open worksheets saved by the current version.

StuartBruff
23-Emerald III
(To:SS_9781956)


@SS_9781956 wrote:

I am pretty new to mathcad so working on and learning. Is it possible to get the result from programming in matrix form. I am trying but getting error. Can someone please help

 

Sam


If you've managed to create a matrix in a program, then either put the name of the matrix as the last line of your program or use the return operator at the point at which you have completed your desired calculation.

 

Look at the Mathcad Help for examples.

 

https://support.ptc.com/help/mathcad/r7.0/en/index.html#page/PTC_Mathcad_Help%2Fabout_programs.html%23

 

https://support.ptc.com/help/mathcad/r7.0/en/index.html#page/PTC_Mathcad_Help%2Foperators_for_exiting_loops_and_programs.html

 

An example of return with the try/on_error operator:

 

As Werner says, if you need specific help, please post a worksheet showing your attempts so far.   That way you will likely get more tailored advice (and don't worry about the 'quality' of your worksheet - we've all written worse!).

 

Cheers,

 

Stuart

 

https://support.ptc.com/help/mathcad/r7.0/en/index.html#page/PTC_Mathcad_Help%2Fexample_using_the_try_on_error_operator.html%23wwID0ED26R

LucMeekes
23-Emerald III
(To:SS_9781956)

Yes, it is possible. See e.g.:

LucMeekes_0-1630502002387.png

But you should attach your worksheet

 

Success!
Luc

My bad! I have attached the worksheet 

LucMeekes
23-Emerald III
(To:SS_9781956)

So you are using Prime 7.

LucMeekes_0-1630503177591.png

 

The problem is not with returning a matrix, you are trying to compare a vector with a scalar, that's not possible. You can only compare apples with apples...

One way is iterate through the vector, comparing:

LucMeekes_1-1630503228736.png

Note that you will NOT get numeric results of 00, since 00 numerically is just 0.

Another way is to compare arrays and use vectorisation, e.g.:

LucMeekes_1-1630504198164.png

 

Success!

Luc

 

Werner_E
25-Diamond I
(To:SS_9781956)

As Luc already wrote, you have to iterate through your vectors, either by using a range variable, a program with a for-loop or by using vectorization.

Vectorization is quite convenient, but Prime won't allow to vectorize a comparison like AA<10 directly. But you can define a function which compares its argument with a given value and then call that function vectorized with your vector as argument.

Using a function may be convenient if you need the same or a similar comparison of a vector with a value more than once in your sheet. If the value you compare with (10 in your example) changes, you may make it the second argument of your function.
Its a matter of personal taste if you prefer the programmed if-branch or the if-function.

Werner_E_0-1630508930190.png

 

"Its a matter of personal taste if you prefer the programmed if-branch or the if-function."

 

Well, not really.  The "if-function" works in Prime Express where programming "is a premium feature," and doesn't.

Werner,

Is it possible to use the equation within the program? With the results obtained i tried to use the row operator but it still remain matrix within a matrix and that is the reason I cannot use in later programmes. Thank you for your help. 

Sam

 

 

Werner_E
25-Diamond I
(To:SS_9781956)

The function sure could be used in a program.

Unfortunately currently I am unable to read Prime 7 files.
In the answer above I was able to look at your file because Luc kindly provided a lP6 version of it.

You can try posting a picture of the program you wrote and I will try to find out why it returns a nested matrix.

StuartBruff
23-Emerald III
(To:SS_9781956)

The row and column operators return arrays (row-vectors and column vectors, respectively), even if that row or column has only a single element.

 

Use the index operator instead.

 

2021 09 09 A.png

 

Stuart

StuartBruff
23-Emerald III
(To:StuartBruff)

It's half-past three in the morning, my brain has gone walkabout, I'm listening to Deep Purple, and I'm not wearing sunglasses.   

 

I'm puzzled.

2021 09 11 A.png

 

What I see with the function head in place of the index operator is what I'd expect to see using the index operator under vectorization.  My mental model of vectorization suggests that it should be working something like:

 

2021 09 11 B.png

or even iterating over the expression,

 

 

2021 09 11 C.png

 

Yet that's not what I'm seeing.  

 

What am I missing here wrt to vectorization and the index operator?

 

Stuart

ttokoro
20-Turquoise
(To:SS_9781956)

image.png

Announcements

Top Tags