Math Programming
Templates can be created for mathematical programming. You can create basic math templates or add iterative program loops, format descriptors and conditional branches to create more complicated mathematical templates.
Basic Templates
The square root of 2 is approximately equal to 1.4.The square root of 2 is approximately equal to 1.4.The square root of 2 is approximately equal to {sqrt(2)}.The square root of 2 is approximately equal to 1.414213.Iterative Program Loops
{for (x=0; x<=5; x++)}
  x={x}, Square root of x={sqrt(x)}
{endloop}x=0, Square root of x = 0
x=1, Square root of x = 1
x=2, Square root of x = 1.41421
x=3, Square root of x = 1.73205
x=4, Square root of x = 2
x=5, Square root of x = 2.23607Format Descriptors
{for (x=0; x<=5; x++)}
x={x}, Square root of x={sqrt(x), %5.3f}
{endloop}x=0, Square root of x = 0.000
x=1, Square root of x = 1.000
x=2, Square root of x = 1.414
x=3, Square root of x = 1.732
x=4, Square root of x = 2.000
x=5, Square root of x = 2.236{'This template evaluates the square root of}
{'the numbers 0 through 5}
{for (x=0; x<=5; x++)}
  x={x}, Square root of x={sqrt(x), %5.3f}
{endloop}x=0, Square root of x = 0.000
x=1, Square root of x = 1.000
x=2, Square root of x = 1.414
x=3, Square root of x = 1.732
x=4, Square root of x = 2.000
x=5, Square root of x = 2.236Conditional Branches
{'This template evaluates the square root of the}
{'numbers 0 through 5 and prints the output when}
{'the value of the square root is less than or}
{'equal to 1.5}
{for (x=0; x<=5; x++)}
  {if (sqrt(x)<=1.5)}
     x={x}, Square root of x={sqrt(x), %5.3f}
  {endif}
{endloop}x=0, Square root of x = 0.000
x=1, Square root of x = 1.000
x=2, Square root of x = 1.414Multiple Output Files
{ofile = {"st_sqr.out", "st_sqrt.out", "st_sine.out"}}
{open ofile[0]}
  {for (x=0; x<=5; x++)}
     x={x}; Square of x= {x^2, %5.3f}
  {endloop}
{close}
{open ofile[1]}
  {for (x=0; x<=5; x++)}
     x={x}; Square root of x= {sqrt(x), %5.3f}
  {endloop}
{close}
{open ofile[2]}
  {for (x=0; x<=5; x++)}
     x={x}; Sine of x= {sin(x), %5.3f}
  {endloop}
{close}Solving Linear Equations
The following template uses vector and matrix functions and operators to solve a linear system of equations.
3x + 4y + 9z = 29
   5x - 3y +  z = 16
    x +  y +  z =  4
{x_coeffs = {  3,  5, 1 }  }
{y_coeffs = {  4, -3, 1 }  }
{z_coeffs = {  9,  1, 1 }  }
{rhs      = { 29, 16, 4 }' }
{lhs = {x_coeffs, y_coeffs, z_coeffs}' }
{format, %5.2f, matrix}
coefficient matrix:
{lhs}
right hand side:
{rhs}
determinant:
{determinant(lhs)}
inverse:
{inverse(lhs) , %7.4f}
inverse times original:
{inverse(lhs) * lhs}
answer:
{inverse(lhs) * rhs}This template produces the following output.
3x + 4y + 9z = 29
5x - 3y +  z = 16
x +  y +  z =  4|    3.00    4.00    9.00   |
|    5.00   -3.00    1.00   |
|    1.00    1.00    1.00   ||   29.00   |
|   16.00   |
|    4.00   |44.00|   -0.0909    0.1136    0.7045   |
|   -0.0909   -0.1364    0.9545   |
|    0.1818    0.0227   -0.6591   ||    1.00    0.00    0.00   |
|    0.00    1.00    0.00   |
|    0.00    0.00    1.00   ||    2.00   |
|   -1.00   |
|    3.00   |Multiple statements can be placed between a single set of braces, { }. Additionally, multiple statements can be placed on the same line by separating the statements with semi-colons, ;. A semi-colon is not required at the end of the line.
Placing multiple statements on one line or several statements between one set of braces gives you flexibility in the way you write your templates.
{
 pt1 = {10.1, 20.2, 30.3}; pt2 = {11.1, 21.2, 33.3};
 diff = pt1 - pt2
 dist = sqrt(diff[0]^2+diff[1]^2+diff[2]^2)
}
The distance between pt1 and pt2 is {dist}.The distance between pt1 and pt2 is 3.31662.{  
 'Solution to the First Order Differential Equation,
 'Initial Value Problem: df/dx= -f + x + 1 where f(0)= 1
 'using Euler, Modified Euler and Runge Kutta explicit
 'integration techniques.
}
{
 n=10
 x = array(n+1)
 Fexact = array(n+1)
 Feu = array(n+1)
 Fme = array(n+1)
 Frk = array(n+1)
 Fexact[0] = 1; Feu[0] = 1; Fme[0] = 1; Frk[0] = 1;
 h=1/n
}
-X-    -Fexact-   -Feuler-  -Fmodeuler- -Frungkutta-
{for(i=0; i<10; i++)}
 {
    x[i+1] = (i+1) * h
   'Exact Solution
     Fexact[i+1] = x[i+1] + exp(-x[i+1])
   'Euler Explicit Integration
     g = -Feu[i] + x[i] + 1
     Feu[i+1] = Feu[i] + h*g
   'Modified Euler Integration
     g_me1 = -Fme[i] + x[i] + 1
     F_me = Fme[i] + 0.5*h*g_me1
     g_me2 = -F_me + (x[i]+0.5*h) + 1
     Fme[i+1] = Fme[i] + h*g_me2
   'Runge Kutta
     k1 = -Frk[i] + x[i] + 1
     k2 = -(Frk[i] + 0.5*h*k1) + x[i] + 0.5*h + 1
     k3 = -(Frk[i] + 0.5*h*k2) + x[i] + 0.5*h + 1
     k4 = -(Frk[i] + h*k3) + x[i] + h + 1
     Frk[i+1] = Frk[i] + (h/6)*(k1+2*k2+2*k3+k4)
 }
{endloop}
{
table(x, Fexact, Feu, Fme, Frk, "%4.2f  %9.6f  %9.6f  %9.6f    %9.6f", 0, 10)
}-X-    -Fexact-   -Feuler-  -Fmodeuler- -Frungkutta-
0.00   1.000000   1.000000   1.000000     1.000000
0.10   1.004837   1.000000   1.005000     1.004838
0.20   1.018731   1.010000   1.019025     1.018731
0.30   1.040818   1.029000   1.041218     1.040818
0.40   1.070320   1.056100   1.070802     1.070320
0.50   1.106531   1.090490   1.107076     1.106531
0.60   1.148812   1.131441   1.149404     1.148812
0.70   1.196585   1.178297   1.197210     1.196586
0.80   1.249329   1.230467   1.249975     1.249329
0.90   1.306570   1.287420   1.307228     1.306570
1.00   1.367879   1.348678   1.368541     1.367880