Skip to main content
6-Contributor
April 16, 2022
Solved

Using If Statements with Matrices

  • April 16, 2022
  • 1 reply
  • 3876 views

Hi,

I need help with using if statements with matrices. I don't think masking will help here since the code should be able to determine if the friction angle is 0 or not. 

 

CF_10130026_0-1650138957139.png

If anyone could help find a solution, I'd really appreciate it. This is my 3rd week of using mathcad - currently trying to transfer all our company's geotechnical excel worksheets to mathcad.

Best answer by Werner_E

One would expect that if you vectorize the expression you created it should work as expected. But unfortunately Prime does not allow to vectorize a comparison operator like ">".

One possible way out is to write a program which cycles through all the vector elements using a for-loop and creates the desired vector of values:

Werner_E_0-1650141667346.png

Another way is to write a utility program which does the comparison and then call this program vectorized (which is something which Prime would allow ;-):

Werner_E_1-1650141771225.png

Of course you could also use the if-function instead of the if-statement. It may be less clear but is more compact and also works in Express:

Werner_E_2-1650141955954.png

 

The screenshot you try to duplicate does not state what should happen if the angle is negative!
I followed your attempt which treats negative values like zeros.

 

1 reply

Werner_E25-Diamond IAnswer
25-Diamond I
April 16, 2022

One would expect that if you vectorize the expression you created it should work as expected. But unfortunately Prime does not allow to vectorize a comparison operator like ">".

One possible way out is to write a program which cycles through all the vector elements using a for-loop and creates the desired vector of values:

Werner_E_0-1650141667346.png

Another way is to write a utility program which does the comparison and then call this program vectorized (which is something which Prime would allow ;-):

Werner_E_1-1650141771225.png

Of course you could also use the if-function instead of the if-statement. It may be less clear but is more compact and also works in Express:

Werner_E_2-1650141955954.png

 

The screenshot you try to duplicate does not state what should happen if the angle is negative!
I followed your attempt which treats negative values like zeros.

 

23-Emerald V
April 16, 2022

One could also make the comparison function a local function ...

 

2022 04 16 b.png

 

I think Prime will allow vectorization of the comparison operators; it's "if" that it doesn't like (for the baffling reason that "if" is a ""pseudo function").

 

2022 04 16 b.png

 

Stuart

25-Diamond I
April 17, 2022

I think Prime will allow vectorization of the comparison operators; it's "if" that it doesn't like (for the baffling reason that "if" is a ""pseudo function").

 

2022 04 16 b.png


Yes, I guess you are right.  Vectorization is even done implicitly in that case

Werner_E_0-1650156432121.png