Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
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
Solved! Go to Solution.
@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
@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
You recently asked the same question using a different user account!!
-> https://community.ptc.com/t5/PTC-Mathcad/Syntax-Questions/m-p/754212/highlight/true#M197798
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.