×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Programming Message in MathCad 14

## Programming Message in MathCad 14

(OP)
The error messages in MathCad programs often do not relate to the error displayed, but I can't find this one. In the attached MathCad V14 sheet two lines before the "while" statement P.stepStart (which was defined just before the "For" statement as 1 psi) has the message "This value has units: Time, Must have units: pressure". The value that I'm assigning to P.stepStart has been defined as psi.

The "cum.target" item is odd. The device I'm working on needs to be able to operate once per minute for some part of the minute and move the target volume. So dividing the 6MCF/day by 24*60 gets the volume that must flow per minute.

David Simpson, PE
MuleShoe Engineering

"Belief" is the acceptance of an hypotheses in the absence of data.
"Prejudice" is having an opinion not supported by the preponderance of the data.
"Knowledge" is only found through the accumulation and analysis of data.

### RE: Programming Message in MathCad 14

Dave,

Couldn't crack your main problem, but your cum target can simply be multiplied by 40*sec, which is what it appears you are doing with the 2/3/(24*60)*day, or 2/3 * min

### RE: Programming Message in MathCad 14

You initialize Output to be a pressure (P.start[i) but then increment it by a time (t.step) at the end of your while loop.

### RE: Programming Message in MathCad 14

(OP)
excognito,
Actually, I knew that, just had forgotten. I run into the problem that you can't define different units for individual cells or columns every time I start a programming exercise. One of these times I'll either remember it or I'll get an error message that actually applies to where the error occurred (probably not). Thanks for pointing it to me.

IRStuff,
It is kind of silly, but I'm going to be running a series of different target volumes and I find it easier to put in the volume and then the conversion, makes it easier for me to find where to adjust the number. What I'm looking for is if I'm moving 6,000 ft^3/day (6 MCF/day), and the valve takes 3 seconds to open and 2 seconds to close, and I operate it once a minute, and the Cv changes continually (but I only have discrete values) how much gas do I have to move in each 0.3 second time step.

David Simpson, PE
MuleShoe Engineering

"Belief" is the acceptance of an hypotheses in the absence of data.
"Prejudice" is having an opinion not supported by the preponderance of the data.
"Knowledge" is only found through the accumulation and analysis of data.

### RE: Programming Message in MathCad 14

Dave,

It's fine; it just looked like some sort of anomalous unit conversion.

### RE: Programming Message in MathCad 14

(OP)
This is the least intuitive programming language I've ever used (and I know 5 languages). I've got it to where a trace will show me that the calcs are right, but can't get them to put the answers somewhere that I can find them.

For each pressure step (the "for" loop in the first sheet) I want to step through the valve settings until I've flowed the target volume. Then I want it to write out the starting pressure, ending pressure, and how many time steps it took. Should be a piece of cake, right? I'm putting the starting pressure in column zero and it is going. I'm trying to put accumulated time in the first column (getting zero in the Output matrix, right answers in the trace). I'm trying to put ending pressure in the second column (I get the first step ending pressure, not the final step ending pressure). Next I'm putting the number of times I execute the While loop. In the last column I put cum gas flowed. and get zero.

When I run the trace I see good numbers for all the columns, but it only runs the first pressure step. I'm sure I'm doing something obvious, but I allocated 3 hours to getting this right and I'm approaching 20 and don't feel any closer to being done. Any help would be greatly appreciated.

David Simpson, PE
MuleShoe Engineering

"Belief" is the acceptance of an hypotheses in the absence of data.
"Prejudice" is having an opinion not supported by the preponderance of the data.
"Knowledge" is only found through the accumulation and analysis of data.

### RE: Programming Message in MathCad 14

(OP)
OK, Stupid move number one was trying to build an array on the fly. I changed it to a programming variable array, then put the name of the variable on the last line of the program and it went into my variable (once I got rid of the subscripts on the Output: value. I'm getting the first line and the first column right. Rest is still broken, but progress.

David Simpson, PE
MuleShoe Engineering

"Belief" is the acceptance of an hypotheses in the absence of data.
"Prejudice" is having an opinion not supported by the preponderance of the data.
"Knowledge" is only found through the accumulation and analysis of data.

### RE: Programming Message in MathCad 14

Seems to be related to where you pick off the outputs. If you move the column assignments around in the code, you get different results. Part of that might be related to when the variables are still in scope.

### RE: Programming Message in MathCad 14

(OP)
That was exactly it. Once I realized that the VB "scope" concept was biting my butt, it only took 5 minutes to get a reasonable and predictable output. When MathCad programs work they are really awesome. I spent about 20 hours writing a performance model that allowed an analysis that would have taken 200 hours by hand and probably 60 hours to write in VB. The error messages in VB are so much more effective that MathCad, but once you debug the MathCad it is pretty cool.

David Simpson, PE
MuleShoe Engineering

"Belief" is the acceptance of an hypotheses in the absence of data.
"Prejudice" is having an opinion not supported by the preponderance of the data.
"Knowledge" is only found through the accumulation and analysis of data.

### RE: Programming Message in MathCad 14

As an alternative, I recommend using the PTC mathcad forums. Lots of professors, PhD's, and power users frequest the forums.

### RE: Programming Message in MathCad 14

(OP)
Been there. Most of the active responder's first position is "of course you are too stupid to use as sophisticated a product as MathCad, go back to floating sticks in the mud". I get really tired of their high an mighty attitude really fast. When outsiders try to help, they tend to circle the wagons and gang up on the new guy who's just trying to help. Don't need it. If that were the only option I would go back to my slide rule.

David Simpson, PE
MuleShoe Engineering

"Belief" is the acceptance of an hypotheses in the absence of data.
"Prejudice" is having an opinion not supported by the preponderance of the data.
"Knowledge" is only found through the accumulation and analysis of data.

### RE: Programming Message in MathCad 14

Sorry to hear that. I frequent the site alot and have always had good help. I've never dabbled with VB script in MathCAD ... haven't needed it. Anon on the PTC forum does lots of VB work. May want to address to him via PM.

### RE: Programming Message in MathCad 14

#### Quote (zdas04)

Been there (PTC Mathcad forum). Most of the active responder's first position is "of course you are too stupid to use as sophisticated a product as MathCad, go back to floating sticks in the mud". I get really tired of their high an mighty attitude really fast. When outsiders try to help, they tend to circle the wagons and gang up on the new guy who's just trying to help. Don't need it. If that were the only option I would go back to my slide rule.
Can you post a reference to the PTC thread (or threads) you are referring to? Such a response is unusual, IME. Most of the active members that I know tend to be very helpful and encouraging of new members.

#### Quote (zdas04)

This is the least intuitive programming language I've ever used (and I know 5 languages).
Programming languages can be somewhat personal in terms of their fit to a person's way of looking at problems. Can you elaborate on why you find Mathcad less intuitive than the other languages you know? I use Mathcad because it's the one I find most intuitive and easy to both implement problems in and pick up again if I don't do any programming for a while (the last time I counted I knew over 30 languages covering assembly level, standard imperative languages, object-oriented languages and functional languages). The Mathcad programming language itself is very primitive - for & while loops, if - otherwise selection, an on error exception handler and return/break/continue ... that's it. The error messages could indeed be improved; I sometimes use the trace command but more often use the return or on error commands to look at intermediate states.

### RE: Programming Message in MathCad 14

(OP)
The very last time I was there was a conversion problem from V11 to V12 (which I actually removed from my computer as a result of my anger at the MathCad forum). I had a complex GENFIT worksheet that was trying to fit an equation to 7 unknowns. I eventually got it to work in V11 by starting with an example that I found on the MathCad forum, but when I installed V12 it stopped working. I posted the sheet and got 25 comments on my choices of variable (too long for FORTRAN purists), my tendency to not use column zero and row zero (sloppy programming), how stupid my program was since the empirical equation I was trying to create had a published solution (that used table lookups that I didn't want to program into the VBA project I was developing the equation for). It was just snotty, snarky, and not on point so I never went back. Must have been about 5 years ago so good luck finding the thread that drove me away (my handle there was the same as everywhere zdas04.

When I got the example that worked in V11, I felt like I needed to give back to the forum and was pretty active for a few months. Just like eng-tips.com, there is a range of contributors from guys who know exactly one way to solve a problem and think that that way was laid down by god to people who have the ability to contribute at a higher level. I kept seeing guys who wanted to help get flamed for their naive posts, and when I tried to help I would get slapped. Not much fun and I only did it for a few months.

As to the programming being counter-intuitive,
• If constructs default to single line. I spent over an hour trying to find a way to make a block conditional before I finally found a quick book that did what I wanted. I was able to copy the example and make it work, but I never found how to do it from a blank line
• Where variables get passed out of the program. I have always assumed that if I assigned a program value to the variable to the right of the = sign, it would go (i.e, Output[i,j] <== PV) but that doesn't seem to work consistently. I finally built a program array the same size as the output array and did OutputTemp[i,j] <== PV, and on the very last line of the program I said Output <== OutputTemp and that worked. Only took 20 years to figure that one out.
• Adding lines. I simply cannot figure out how to add a line without it indenting. What I finally started doing a few years ago is cutting a line at the level I wanted and then adding a line and pasting the cut item back. What a pain, but much less painful that arbitrarily adding 30 lines at every level and then deleting them if not needed
• The FOR construct seems to use different syntax than most range assignments. I do i=0,1;20 to say that I want to assign 0-20 inclusive incremented by 1 to "i". In the FOR construct you do 0;20 to do the same thing and it give you inconsistent results when you add the "1".
Biggest problem is that the error messages (after the typo stuff is resolved) almost never point to where the problem is. I regularly end up accidently assigning a unit to an array and then 10 calculations later an error shows up "units of length time-1 entered where units of length required" or some such. When I try to use trace to find it the program never seems to run to the line where the error was flagged. Generally pretty frustrating.

I use MathCad V14 every day, and it is rare that I don't have 5-6 worksheets open to address issues for various parts of my wide-ranging practice. If I didn't have it I would probably be writing programs in Excel VBA to overcome its many shortcomings.

David Simpson, PE
MuleShoe Engineering

"Belief" is the acceptance of an hypotheses in the absence of data.
"Prejudice" is having an opinion not supported by the preponderance of the data.
"Knowledge" is only found through the accumulation and analysis of data.

### RE: Programming Message in MathCad 14

As for the counter-intuitive features you mention, it may help to reflect that Mathcad started out as an electronic "maths whiteboard" rather than a programming tool - in fact, programming with for loops wasn't introduced until around version 6.

• If constructs default to single line. I spent over an hour trying to find a way to make a block conditional before I finally found a quick book that did what I wanted. I was able to copy the example and make it work, but I never found how to do it from a blank line
It rather looks like the if-otherwise statement was supposed to resemble the standard conditional notation you find in many maths books rather than the conventional if-else structure; this would place the result before the if and the conditional after the if. To create more lines in the if statement, place your cursor in the result placeholder and press ']' or select 'Add Line' from the programming toolbar; the same goes for the otherwise. You can actually add more lines to the if's conditional clause using the same technique.

• Where variables get passed out of the program. I have always assumed that if I assigned a program value to the variable to the right of the = sign, it would go (i.e, Output[i,j] <== PV) but that doesn't seem to work consistently. I finally built a program array the same size as the output array and did OutputTemp[i,j] <== PV, and on the very last line of the program I said Output <== OutputTemp and that worked. Only took 20 years to figure that one out.
I'm not quite sure what you mean, could you post an example (unless you're happy you've got the problem solved, but it may benefit somebody else with the same problem)?
• Adding lines. I simply cannot figure out how to add a line without it indenting. What I finally started doing a few years ago is cutting a line at the level I wanted and then adding a line and pasting the cut item back. What a pain, but much less painful that arbitrarily adding 30 lines at every level and then deleting them if not needed
See the response to the if statement. Use the spacebar/arrow-keys to select the level you want and the Insert key to select the start/end of the selection. Then press ']' or 'Add Line' as many times as you need. You may find Mathcad Prime's programming style more to your liking; PTC took note of some the comments (complaints!) and revised the structure - I believe just pressing Return in a program creates a new line and all if blocks indent the result line.
• The FOR construct seems to use different syntax than most range assignments. I do i=0,1;20 to say that I want to assign 0-20 inclusive incremented by 1 to "i". In the FOR construct you do 0;20 to do the same thing and it give you inconsistent results when you add the "1".
I haven't noticed that; it seems to behave exactly as I'd expect (you can just do i:=0..20 to define a range variable running from 0 to 20 inclusive, Mathcad assumes you mean "0,1"). Can you give an example?

Error reporting is a problem with many applications and Mathcad does indeed suffer from its fair share of rather ambiguous or downright misleading error messages. I don't often use trace, preferring to place return statements at various points throughout a program to identify how far it's got and what it's done. However, trace can be very useful at times.

### RE: Programming Message in MathCad 14

re. indexing. Note that Mathcad defaults to the programmer's convention of starting at 0. You can force Mathcad to start at 1 with ORIGIN:=1.

Mention of Jean and Tom brings back memories. I quit the PTC forum shortly after Tom did. The good news was that there was quite a bit of activity, but something just seemed to be different. Seems like many of the old stalwarts of the Collab are still pretty active in the new forum: StuartBruff, ValeryOchkov, FredKohlhepp, RichardJackson, etc. Jean's departure was a much celebrated event.

### RE: Programming Message in MathCad 14

I thought I hadn't seen you around much on the "Community". I don't frequent it that much myself as it seems to be an awful lot quieter than the Collab was. Actually, I miss having Jean around ... one could learn so much by watching his assertions being comprehensively demolished.

### RE: Programming Message in MathCad 14

I used to be there under my own name; back in the days when using your own name seemed safe.

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!