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
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?
Solved! Go to Solution.
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.
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.
you can do so too:
to which is added the case where w = 0
Thank you both very much. F.M. that's a clever way to handle a 1 or 0 Origin.
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.
Yes, now its ORIGIN-independent.
Because your routine is missing an else statement, you will get a zero in the last column if there is a zero in the first one (nor sure what really should happen in that case as the OP did not state). But in the (I guess very rare) case that the first column is all zero, no fourth column will be created at all. Not sure if that is desirable.
As I think that a program should deal with all possibilities (even if extremely rare), I would add an else branch.
I am not sure if the whole calculation should fail just because of one zero in the first column, but this sure is also an option.
We don't know what Daniel had in mind, so every solution is OK.
Thank you for continuing to work on this. Can you tell me what the purpose is of this part of the program?
I should add that the program won't see a zero in the first column but it's good to add that option.
Hi
In fact you did not say what happens if wpipe is zero.
So, I did that change which, it seems clear, in case that the first column (I should have to write 3 + ori) there is a zero, the loop stops and sends the message that is displayed in the bottom of the image .
Greetings
A quick question; what change do I need to make to the last program return a vector of values instead of a single value?
I think this should work to get the full vector of k-values:
Success!
Luc
Thank you!
You're welcome.