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!

Programming in mathcad 1

Status
Not open for further replies.

jjerman

Industrial
Jul 4, 2008
2
Hallo everyone.
I'm a newuser in M. and I'm trying to "convert" a simple
basic listing to mathcad.
Despite my efforts I still can't get any good result.
Following the prg. (heat transfer).
JJerman


10 alung = .02
20 are = .24 * alung
30 port = .01648
40 qint = 0
100 h = 60
110 t1 = 680
120 t2 = 80
140 FOR i = 1 TO 50
150 q = h * (t1 - t2)
160 qtot = are * q
170 cp = .64545 * (t1 - 500) + 687
180 dt = qtot / (port * cp)
190 t1 = t1 - dt
200 qint = qint + qtot
220 alung = alung + .02
230 NEXT i

 
Replies continue below

Recommended for you

See the attached file. Result is a vector containing several of your program variables. The last statement assigns the elements of Result to different variables. If you are only interested in one variable, say alung, change the last program statement to alung and Result will equal its value.
 
 http://files.engineering.com/getfile.aspx?folder=7c6f0891-8436-45af-90e4-771b810d1010&file=Heat_Transfer_Program.xmcd
It looks like a temperature simulation program simulating the temperature dropping from 680 to 80 degrees. If so this can be simulated in a differential equation a lot more cleanly and accurately but that wasn't what was asked for so I wait.
 
jgrhist,
That was the clearest example of a MathCad program I've ever seen (all of the examples in the book have extra stuff that muddies the water for me). I program in MathCad all the time and it always surprises me when a program works. I can read every line of your program and understand what it is doing and why it is there. Thank you.

David
 
Tom Gutman has responded to your posting in the Mathcad Collab. If you are indeed trying to solve a differential equation, Mathcad has more direct solutions than grinding through a FOR loop.

As Tom suggests, you should look at the original problem in your book, and apply Mathcad directly to the solution, rather than trying to duplicate the results of the BASIC program.

TTFN

FAQ731-376
 
Thanks, David, but all I did was translate the OP's Basic language program to Mathcad. The original program was clear so the translation was clear.

There's no great trick to programming in Mathcad except to realize that there is only one result. All of the other assignments within the program are local only and cannot be used outside the program. Only the last statement is returned as the value. The result can be a matrix, so you can get other values from it.

Most of the programs I use in Mathcad are short ones that probably could be done cleverly without programming, but not nearly as clearly. I use the programs for clarity in documentation as much as anything else.
 
You can get something other than the last value returned by adding a line at the end and specifying which local variable you want returned. That helps with debugging.
 
I understand, I write programs all the time. The problem I have is knowing exactly what all the parts and pieces of the program do. I always find myself guessing what a particular line of a cut-and-paste does, and usually guessing wrong. The program you posted made sense to me and I understood the function of every line and every component. I've never been able to say that before, even on programs that I "wrote" from scratch--there is always some part that I stuck in there because it worked in the past. Clear examples are scarce.

David
 
You can get something other than the last value returned by adding a line at the end and specifying which local variable you want returned. That helps with debugging.
But then the last line is the last value returned. Using the "return" statement instead of assigning a local variable as the last program statement has the same effect. I do think using "return" is preferable because it clarifies what is happening.
 
What is the best way to learn the MathCad syntax of programming?
 
1st thanks everybody!!
2nd the code should compute heat tranfer and temperature
variation in a steel sheet moving through a cooler (1m lenght) where it
is cooled by nitrogen at high speed.
h is the film coefficient evaluate in a condition of
forced convectione inside the cooler.
Of course it could be solved via differential equation
(but I'm not able to use them with mathcad).
thanks again
 
See Tom Gutman's response to your Mathcad collab posting. M14 has both ODE and PDE solving capabilities.

TTFN

FAQ731-376
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor