Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

MathCAD Decision Statement

Status
Not open for further replies.

Cockroach

Mechanical
Jan 17, 2003
1,104
I have the following statements in a MathCAD 14 program:

X=1
Y=2000
XPRIME <== (X + 13) if X < 3
YPRIME <== (Y - 1) if X < 3

I find that the "if" statements are not executing, running the following debug lines generates "variable undefined" error, returned in red text.

Adding the two lines:

X=
Y=

does return 1 and 2000 respectively, so I know that the variables are good prior to the "if" statements.

XPRIME =
YPRIME =

What is wrong with the syntax? What am I missing?

Kenneth J Hueston, PEng
Principal
Sturni-Hueston Engineering Inc
Edmonton, Alberta Canada
 
Replies continue below

Recommended for you

Is this a program or just a worksheet? You seem to be using syntax from a normal worksheet, but you keep refering to a "program."

If possible, could you post your worksheet downsaved as M11?

TTFN

FAQ731-376
Chinese prisoner wins Nobel Peace Prize
 
Yeah, there is some issue with the syntax. I'm careful enough not to manually type the word "if", errors of that nature, picking it off the Program Pallette. But I am fairly new to MathCAD and want to convert several older programs to such a format.

Here is the program. I am correctly reading in the variables, but the decision block is not executing. Don't know why, struggling with the logic somewhat.

Much thanks. Program is attached.

Kenneth J Hueston, PEng
Principal
Sturni-Hueston Engineering Inc
Edmonton, Alberta Canada
 
 http://files.engineering.com/getfile.aspx?folder=584f9652-8b03-4ad8-af70-b3bfa53bb82e&file=Mathcad_-_Julian_Date.pdf
OK, better, but the actual sheet in M11 format would be more useful, so respondents don't have to re-type your equations.

Is this supposed to be a subprogram within Mathcad? You're using programming constructs in step 3, but using regular sheet constructs everywhere else. By program, I refer specifically to a worksheet component typified by a broad vertical bar with an assignment operator on the left, and a sequence of instructions on the right side.

It looks like you're trying to replicate the calculation from Zombeck's Astronomical Formulas, but in programmed function form?

TTFN

FAQ731-376
Chinese prisoner wins Nobel Peace Prize
 
I'm fairly new to MathCAD, only been using it for simple engineering computations. I have several FORTRAN, C++ and Visual Basic programs concerning astrometric computation, some of them dating back twenty years or so, and was converting the Julian Date one as a simple exercise.

The MathCAD syntax is something mysterious, I have been using website examples and some of the Help Tutorials to get a better understanding, but this one has proven to be more problematic. There is not a lot of reference material out there, "MathCAD for Dummies", that sort of thing.

The source algorithm for this one was Duffet-Smith. The program is not fully debugged yet, I need to add the October 1583 delimiter, but was working with the January/February correction at the time this "if statement" problem arose. Seems simple enough, just not executing properly.

Kenneth J Hueston, PEng
Principal
Sturni-Hueston Engineering Inc
Edmonton, Alberta Canada
 
Thanks Occupant. Let me give that one a whirl!

Kenneth J Hueston, PEng
Principal
Sturni-Hueston Engineering Inc
Edmonton, Alberta Canada
 
 
I didn't like what I posted previously, I discovered some errors in there. So I did it again, the solution is analogous to yours, but I didn't quite like it because of the "MM+13", I think it should be "MM+12". As you can see on the attached, the in line "if" can be used as well as the programmatic one (the one with the bars)
 
 http://files.engineering.com/getfile.aspx?folder=bd7b05c0-56f5-410d-8024-ec9e8e2ef0f4&file=Gregorian_to_Julian(2).jpg
Thanks again Occupant. I still don't understand why that conditional "if" statement failed to execute in the original MathCAD program. Any insight to this?

Kenneth J Hueston, PEng
Principal
Sturni-Hueston Engineering Inc
Edmonton, Alberta Canada
 
The operator <- is for local definitions within a program. This allows you to create variables that a program uses for intermediate steps that aren't needed outside the program. These variables don't exist outside of the program so can't be called by an external function. To store something that can be used later in the worksheet use :=.

Peter
 
Thanks PStuckey, I figured some sort of "global" verses "local" variable thing after reading such localization inside nested loops. Kind of strange to me, but then again, I'm a newbie to MathCAD and am trying to get more out of it than simple formulation with calculation.

Anyway, thanks to this threads respondants, using all the inputs, I got the program intended, which is attached below. Not perfect yet, but will work on AD years prior to 1582 Oct 15 and cases involving BC.

Kenneth J Hueston, PEng
Principal
Sturni-Hueston Engineering Inc
Edmonton, Alberta Canada
 
 http://files.engineering.com/getfile.aspx?folder=9d5c2b02-3fb8-4d6c-977d-fd1328c0cc94&file=Julian_Date.xmcd
Here is the program, probably needs to be cleaned up a bit.

It runs correctly for years after 1582 October 15, and correct again for years -1 AD to 1582 October 15. For some odd reason I am exactly one day out for the BC years.

Thanks again.

Kenneth J Hueston, PEng
Principal
Sturni-Hueston Engineering Inc
Edmonton, Alberta Canada
 
 http://files.engineering.com/getfile.aspx?folder=cc7b1cee-6e5c-46df-a09b-7e2ec277ad40&file=Julian_Date_-_Meeus.xmcd
Status
Not open for further replies.

Part and Inventory Search

Sponsor