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
>
|
|
>
|
|
Read the Programming Guide to learn how to write procedures
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.
>
|
|
>
|
|
>
|
|
Now generate Python code for the two procedures
>
|
|
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)
| |
>
|
|
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 let you write your procedures using a traditional text input interface that features several IDE-like features, such as
•
|
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
|
|