Skip to main content
1-Visitor
March 23, 2017
Solved

Array column creation with if statement?

  • March 23, 2017
  • 3 replies
  • 7338 views

The attached Mathcad Prime 3.1 worksheet (and screenshot) adds a 4th column to the array (or is it a matrix?) with the weight of pipe filled with water per foot. Creating the forth column with a definition works. The if statement tries to accomplish the same goal, what am I doing wrong?

Best answer by Werner_E

Either use a different (dummy) variable instead of w.pipe[i,3 or even better omit the local assignment and use just the right hand side expression on its own.

You should also add an else statement in case a value in the first column is zero.

3 replies

Werner_E25-Diamond IAnswer
25-Diamond I
March 23, 2017

Either use a different (dummy) variable instead of w.pipe[i,3 or even better omit the local assignment and use just the right hand side expression on its own.

You should also add an else statement in case a value in the first column is zero.

21-Topaz II
March 24, 2017

you can do so too:

wpipe.jpg

to which is added the case where w = 0

dsochor1-VisitorAuthor
1-Visitor
March 24, 2017

Thank you both very much. F.M. that's a clever way to handle a 1 or 0 Origin.

25-Diamond I
March 24, 2017

Yes, but to be fully ORIGIN-independent one has to change the second indices 0,1,2,3 to ori, ori+1, etc., too. Otherwise you will run into an error in case ORIGIN is not 0.

BTW, here's another way to achieve what you want using the if-command. I changed two values in the first column to zero to show the effect of the "else"-branch.

dsochor1-VisitorAuthor
1-Visitor
March 27, 2017

A quick question; what change do I need to make to the last program return a vector of values instead of a single value?

23-Emerald IV
March 27, 2017

I think this should work to get the full vector of k-values:

Success!

Luc

dsochor1-VisitorAuthor
1-Visitor
March 27, 2017

Thank you!