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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Using If Statements with Matrices

CF_10130026
6-Contributor

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. 

 

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.

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(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:

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.

 

View solution in original post

4 REPLIES 4
Werner_E
25-Diamond I
(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:

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.

 

StuartBruff
23-Emerald III
(To:Werner_E)

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

Werner_E
25-Diamond I
(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").

 

2022 04 16 b.png


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

Werner_E_0-1650156432121.png

 

CF_10130026
6-Contributor
(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.

CF_10130026_0-1650168467707.png

 

Announcements

Top Tags