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

## Syntax Question  4-Participant

## Syntax Question

Hello All,

I am a total newbie and I am trying to read through some previous mathcad solutions and am unsure what this syntax means, does anyone have any idea? Is it saying if mod(j,2)=0 AND mod(j,4)=2,-1,1) then return 0 (screenshot 1)? I have a older version of mathcad so I am also unsure how to write this in my version (screenshot 2). I have also attached the problem document where I found this (PDF).

Best Regards,

MrTims

1 ACCEPTED SOLUTION

Accepted Solutions  23-Emerald II
(To:MrTims)

@MrTims wrote:

Hello All,

I am a total newbie and I am trying to read through some previous mathcad solutions and am unsure what this syntax means, does anyone have any idea? Is it saying if mod(j,2)=0 AND mod(j,4)=2,-1,1) then return 0 (screenshot 1)? I have a older version of mathcad so I am also unsure how to write this in my version (screenshot 2). I have also attached the problem document where I found this (PDF).

Yes, that is what the expression is doing.

if functions take the form:

if (condition, do-if-true, do-otherwise)

What you have is an if function with another if function as the do-if-true expression.

Regarding your program - the 1 should go in the first placeholder after the if mod-4 test and an otherwise expression with -1 should go in the 2nd placeholder.  Your last line should be an otherwise to match the first if test... otherwise the program will always return 0.

if programming expressions in Mathcad 15 (or earlier down to Mathcad 7) take the form:

do-if-true if condition

for single line expressions or for multi-line expressions, as you have above,

if condition
do-if-true
do-if-true

The otherwise (else) expression is optional in M15, and has a similar structure

do-otherwise otherwise

or

otherwise
do-otherwise
do-otherwise

A programming equivalent for the if function would be something like:

``````if mod(j,s)=0
"j is even"
1 if mod(j,4)=2
-1 otherwise
0 otherwise``````

(I put the string in there just to force Mathcad to indent the do-true expression and make it easier to follow. Like everything, you get used to how if-otherwise works with practice.)

Stuart

3 REPLIES 3  23-Emerald II
(To:MrTims)

@MrTims wrote:

Hello All,

I am a total newbie and I am trying to read through some previous mathcad solutions and am unsure what this syntax means, does anyone have any idea? Is it saying if mod(j,2)=0 AND mod(j,4)=2,-1,1) then return 0 (screenshot 1)? I have a older version of mathcad so I am also unsure how to write this in my version (screenshot 2). I have also attached the problem document where I found this (PDF).

Yes, that is what the expression is doing.

if functions take the form:

if (condition, do-if-true, do-otherwise)

What you have is an if function with another if function as the do-if-true expression.

Regarding your program - the 1 should go in the first placeholder after the if mod-4 test and an otherwise expression with -1 should go in the 2nd placeholder.  Your last line should be an otherwise to match the first if test... otherwise the program will always return 0.

if programming expressions in Mathcad 15 (or earlier down to Mathcad 7) take the form:

do-if-true if condition

for single line expressions or for multi-line expressions, as you have above,

if condition
do-if-true
do-if-true

The otherwise (else) expression is optional in M15, and has a similar structure

do-otherwise otherwise

or

otherwise
do-otherwise
do-otherwise

A programming equivalent for the if function would be something like:

``````if mod(j,s)=0
"j is even"
1 if mod(j,4)=2
-1 otherwise
0 otherwise``````

(I put the string in there just to force Mathcad to indent the do-true expression and make it easier to follow. Like everything, you get used to how if-otherwise works with practice.)

Stuart  24-Ruby V
(To:MrTims)

You recently asked the same question using a different user account!!  6-Contributor
(To:Werner_E)

Yes I know haha. I wanted to make a new account with my gmail instead of my edu, but I didn't know you had to wait for mod approval with new users lol. Announcements