MaplePortal/Procedures - Maple Help

Home : Support : Online Help : MaplePortal/Procedures

 Procedures and Programming

 Introduction

Maple lets you write programs (also known as procedures) to automate your work, batch process data files, and more.

Unlike low-level languages, you can use high level math tools in Maple procedures.  This procedure, for example, calculates the friction factor for liquid flow in a pipe; the fsolve function is used to numerically solve an equation

 > 
 > $\mathrm{friction}\left(0.0001,0.1,5000\right)$
 ${0.03849535900}$ (1)

Read the Programming Guide to learn how to write procedures

 Code Generation

You can also convert Maple procedures to other languages. Simply use Maple's interactive development environment to develop, optimize and validate your code, and then generate code for your target language.

These two procedures, for example, replaces the use of fsolve in the procedure above with a bisection method. The procedures are then converted to Python.

 >
 >
 > $\mathrm{bisectionColebrook}\left(\mathrm{friction},0.0001,0.1,0.0001,0.1,5000\right)$
 ${0.03848930665}$ (2)

Now generate Python code for the two procedures

 > $\mathrm{CodeGeneration}\left[\mathrm{Python}\right]\left(\mathrm{bisectionColebrook}\right)$
 def bisectionColebrook (   friction,   a,   b,   e,   Dia,   Rey):     epsilonABS = 0.1e-4     epsilonSTEP = 0.1e-4     atemp = a     btemp = b     while (epsilonSTEP <= btemp - atemp or epsilonABS <= abs(friction(atemp, e, Dia, Rey)) and epsilonABS <= abs(friction(btemp, e, Dia, Rey))):         c = atemp / 2 + btemp / 2         if abs(friction(c, e, Dia, Rey)) <= 0:             break         elif friction(atemp, e, Dia, Rey) * friction(c, e, Dia, Rey) < 0:             btemp = c         else:             atemp = c     return(atemp)
 > $\mathrm{CodeGeneration}\left[\mathrm{Python}\right]\left(\mathrm{friction}\right)$
 import math def friction (   f,   e,   Dia,   Rey):     return(-2 * math.log10(e / 0.37e1 / Dia + 0.251e1 / (Rey * math.sqrt(f))) - 0.1e1 / math.sqrt(f))

 Code Edit Regions

Code Edit Regions let you write your procedures using a traditional text input interface that features several IDE-like features, such as

 • syntax highlighting
 • bracket matching
 • command completion
 • automatic text wrapping
 • optional line number display
 • and automatic indenting.

Right-click on the following Code Edit region and select "Collapse Code Edit Region" to collapse it

 > 

 Applications Maximize the Efficiency of a Rankine Cycle Organic Rankine Cycle