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

3-Visitor

## 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
23-Emerald I
(To:CW_9977191)

See if this helps

Success!
Luc

5 REPLIES 5
23-Emerald I
(To:CW_9977191)

See if this helps

Success!
Luc

3-Visitor
(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.

24-Ruby IV
(To:CW_9977191)

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?

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

3-Visitor
(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.

23-Emerald I
(To:CW_9977191)