Skip to main content
8-Gravel
September 1, 2021
Solved

Programming and scalar

  • September 1, 2021
  • 3 replies
  • 4816 views

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

Best answer by Werner_E

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

 

3 replies

25-Diamond I
September 1, 2021

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.

23-Emerald V
September 1, 2021

@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

23-Emerald IV
September 1, 2021

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

LucMeekes_0-1630502002387.png

But you should attach your worksheet

 

Success!
Luc

8-Gravel
September 1, 2021

My bad! I have attached the worksheet 

23-Emerald IV
September 1, 2021

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