MaplePortal/Procedures - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : MaplePortal/Procedures


Procedures and Programming

Back to Portal



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


frictionproce,Dia,Rey    if not typeRey,numeric or not typee,numeric       then 'frictionRey,e':    else       if Rey>2300 then         fsolve 1f=2log10e3.7Dia+2.51Rey f:       else          64Rey       end if:     end if:end proc:





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.


friction  proc f, e, Dia, Rey       return 2  log10e3.7  Dia+2.51Rey  f1f:end proc:

bisectionColebrook  proc friction&comma; a&comma; b&comma; e&comma; Dia&comma; Rey      local epsilonABS&comma; epsilonSTEP&comma; c&comma; atemp&comma; btemp&colon;     epsilonABS  0.1&ExponentialE;-4&colon;     epsilonSTEP  0.1&ExponentialE;-4&colon;     atemp  a&colon;     btemp  b&colon;      while epsilonSTEP  btempatemp or epsilonABS  absfrictionatemp&comma; e&comma; Dia&comma; Rey            and epsilonABS  absfrictionbtemp&comma; e&comma; Dia&comma; Rey do         c  atemp2&plus; btemp2&colon;         if absfrictionc&comma; e&comma; Dia&comma; Rey  0 then            break         elif frictionatemp&comma; e&comma; Dia&comma; Reyfrictionc&comma; e&comma; Dia&comma; Rey < 0 then            btemp  c         else            atemp  c         end if      end do&colon;     return atemp&colon;end proc&colon;




Now generate Python code for the two procedures


def bisectionColebrook (
    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:
        elif friction(atemp, e, Dia, Rey) * friction(c, e, Dia, Rey) < 0:
            btemp = c
            atemp = c


import math

def friction (
    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





Code Generation for a Robot Arm

Maximize the Efficiency of a Rankine Cycle

Organic Rankine Cycle