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

Syntax Questions

UK_9916373
5-Regular Member

Syntax Questions

Hello All,

 

Sorry for previous posts did not tag a answer, I am a newbie, will not happen again haha. For this post 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.

1 ACCEPTED SOLUTION

Accepted Solutions

Additionally to what Alan already explained I'd like to make clear to you that "if" exists in two flavours.

The first one is the if-function which is used in your original document an the syntax was already explained by Alan. Its similar to the if-function in a spreadsheet like Excel or Calc and if nested it can be confusing and quite hard to read. The advantage in Prime is that the if function is not a premium function and therefore can also be used in the free Prime Express. In Mathcad 15 (and below you don't need to use the programming toolbar to use the if-function, just type it in.

 

Additionally there is also the if construct in a program and this is what you had tried, given the picture you sent. IMHO using a multiline program may take up more space but is significantly easier to read (and debug, if necessary).

Here are a few way to achieve the very same result, done in Mathcad 15, which may be the version you are using. I save the file in the format of Mathcad 11 to further increase the likelihood that you can actually read the file.

I hope this helps clarify your question.

Werner_E_0-1634825010961.png

 

View solution in original post

4 REPLIES 4

if(a,b,c) means if a is true return b, if a is false return c.

 

This can be nested, so  if(a, if(x,y,z), c)  means if a is true then  if x is true return y, if x is false return z,  if a is false return c

 

So, with j as an integer,   if(mod(j,2)=0,  if(mod(j,4)=2, -1,1), 0) means

 

if j is even (ie mod(j,2)=0) then:  if the remainder when dividing j by 4 is 2, return -1,  if the remainder when dividing j by 4 isn't 2, return 1,

if j is odd then return 0.

 

Alan

 

 

 

UK_9916373
5-Regular Member
(To:AlanStevens)

Thank you very much Alan!

Additionally to what Alan already explained I'd like to make clear to you that "if" exists in two flavours.

The first one is the if-function which is used in your original document an the syntax was already explained by Alan. Its similar to the if-function in a spreadsheet like Excel or Calc and if nested it can be confusing and quite hard to read. The advantage in Prime is that the if function is not a premium function and therefore can also be used in the free Prime Express. In Mathcad 15 (and below you don't need to use the programming toolbar to use the if-function, just type it in.

 

Additionally there is also the if construct in a program and this is what you had tried, given the picture you sent. IMHO using a multiline program may take up more space but is significantly easier to read (and debug, if necessary).

Here are a few way to achieve the very same result, done in Mathcad 15, which may be the version you are using. I save the file in the format of Mathcad 11 to further increase the likelihood that you can actually read the file.

I hope this helps clarify your question.

Werner_E_0-1634825010961.png

 

View solution in original post

UK_9916373
5-Regular Member
(To:Werner_E)

This is fantastic. Thank you Alan and Werner!

Announcements
Check out the latest
Mathcad Tip
"PTC Mathcad 15 / Prime 1-6 Update."