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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Help with For/If statements

BG_7818704
4-Participant

Help with For/If statements

Hi,

I am trying to replicate a programming block that my professor sent me to implement into a larger mathcad sheet/program. However, I'm getting a bit lost on the formatting of it. The screencap of the correct block is shown below.

BG_7818704_0-1611765664339.png

And then there's my attempt at it so far. I'm mostly confused about the value the if statement falls back on to if the following statements fail.

BG_7818704_1-1611765732548.png

Any help would be appreciated! I'm used to just using MathCad for "cheat" sheet style calculations, so I'm lost on the programming logic of the language.

1 REPLY 1

You should always attach your worksheet when asking a question and its a good idea to mention which flavor (Prime or real Mathcad) and version of the software you are using.

I guess you are using Mathcad 15.

The program shown simply creates a new matrix consisting only of the rows of matrix pM (or at least the first three columns of it), where the value in the first column is approx. 2 (within a distance of 0.005).

So if the "if" statement fails, no rows is selected and nothing has to be done.

 

The first error I see is that you did not use matrix indices when writing pM[i,1.

Then you probably are confused because the statement for the if statement are not indented and placed in the next line? The reason is that Mathcad is doing so only if there are more than one statement in the if.  If there is only one statement, its placed to the left of the "if".

So put your first statement in the black placeholder to the left of the "if" and then add a new line (either from the palette or by pressing "]") and you will get the structure you are looking for.

 

Attached is a Mathcad 15 file along with a couple of alternative ways (without error checks) to achieve the same effect (assuming the ORIGIN should be changed to 1 and that pM is a matrix with just 3 columns)

Werner_E_1-1611772138007.png

 

 

 

Top Tags