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

5-Regular Member

## Using If Statements with Matrices

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.

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.

1 ACCEPTED SOLUTION

Accepted Solutions
24-Ruby V
(To:CF_10130026)

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:

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 ;-):

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:

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.

4 REPLIES 4
24-Ruby V
(To:CF_10130026)

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:

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 ;-):

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:

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 II
(To:Werner_E)

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

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").

Stuart

24-Ruby V
(To:StuartBruff)

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").

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

5-Regular Member
(To:Werner_E)

Thank you so much! Went with the 1st option but the other options you provided will definitely help me a lot in the very near future.

Announcements