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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

Mathcad Prime - Writing an if else program to evaluate each row in a table

CW_9977191
4-Participant

Mathcad Prime - Writing an if else program to evaluate each row in a table

Hello Everyone.

 

Ive not got much experience in Mathcad so hoping you can help me with a simple program I have been trying to write.  Basically I have set up a table, with two columns "a" and "b" and what I was looking to do was write a program that evaluates an if/else statement for each row.  If a is greater than 2 then carry out a+b if a is not greater than 2 then carry out a-b. 

 

At the moment I can get it to work for the first part however when I add in the else statement it looks to me like a single row complying with the else statement means that this is applied to every single row rather than just the individual row. 

 

Is it possible to have this program evaluating each row independently of each other? 

 

I've attached my file and a screenshot of the sheet as well.  

 

If you guys need more information please let me know.  Also I am no expert so if there are better ways of doing this, anything I have done that I shouldnt etc. please let me know.  

 

Thank you.  

1 ACCEPTED SOLUTION

Accepted Solutions
LucMeekes
23-Emerald III
(To:CW_9977191)

See if this helps

LucMeekes_0-1624644206585.png

Success!
Luc

View solution in original post

5 REPLIES 5
LucMeekes
23-Emerald III
(To:CW_9977191)

See if this helps

LucMeekes_0-1624644206585.png

Success!
Luc

CW_9977191
4-Participant
(To:LucMeekes)

Thank you Luc, I have used your examples here and got it working.  Thanks for taking the time to help out and also for your additional work further explaining my issues in the sheet below.  

How about writing a function that does what you want for two simple scalar arguments and then calling this function vectorized with the two vectors as the current arguments?

Werner_E_0-1624649298769.png

BTW, while I would consider it good habit, its not mandatory in case of this function to use the two "return" statements. It works equally well without them, too.

 

Prime6 worksheet attached

 

CW_9977191
4-Participant
(To:Werner_E)

Hi Werner, 

 

Thank you for this.  I hadn't actually thought about doing it this way.  

 

My hope is to apply this to a more complex equation with more variables so I wasn't really thinking down this route as I would end up with a long function call out, eg f(a,b,c,d,e,f,g,h,i) however I think it would still work.  I will have a play about with both your suggestion and Lucs and see what works best for me.  

 

Thank you for taking the time to help.     

 

LucMeekes
23-Emerald III
(To:CW_9977191)

Here's some more info. (see attachment)

 

Success!

Luc

Top Tags