Mate - online symbolic calculator by Tusanga


Calculation
- Getting started
- Expressions
- Statements
- Functions
- Examples
- Questions
Resources

Calculation / Statements

The following is meant as a reference guide for the system. It first describes the different statements that the system understands. In addition to statements and expressions, comments are also provided for. Input beginning with the ' character (normally the evaluation delay operator) is interpreted as a comment.

      
Variable assignment statement.   Multiple variable assignment statement.   Function assignment statement.   Matrix assignment statement.   Plot statement   For statement   While statement   If statement   Keyword statement   Expression statement   Expression statement with numbersystem   Procedure definition statement   Procedure execution statement   


Statements

Several types of statements are supported.

Variable assignment statement.
Syntax : <variable> := <expression>
Example : x:= 5

Multiple variable assignment statement.
Syntax : { <var1>, ... } := <expression>
Example : {x,y} := {5,7}

Function assignment statement.
Syntax : <function> ( <var1>, ... ) := <expression>
Example : f(x,y) := x+y

Matrix assignment statement.
One or more elements in a matrix are assigned a value. If the matrix does not exist, it is created in the environment. If the row and column index selects an element outside the current matrix, the matrix is expanded to include the selected element. Other elements are then assigned the value zero.
Syntax : <matrix-variable>[row index, column index] := <expression>
Example : M[2,3]:=2*q


Use ... as row and/or column index to include all rows/columns.
Example : M[2,...] := {1,2,3}


The row index can be omitted. It is interpreted as follows.
Syntax : <matrix-variable>[column index] = <matrix-variable>[..., column index]
Example : M[2] := 5


Functions, variables including matrices and procedures share name-space. Names are case-sensitive.


The following words are keywords and should not be used as names for variables and matrices:
who, restart, version, div, mod, true, false, and, nand, or, nor, not, xor, if, then, else, while, do, end, for, to, step, next, kill, quit, done, exit, stop, i, pi, e, NaN, inf.

Plot statement
The statement plots one dataset.
Syntax : plot(<plot type>, <plot symbol>, X, Y)
Syntax : plot(<plot type>, <plot symbol>, Y)
Syntax : plot(<plot type>, <plot symbol>, X, Y, a, b, c)
The plot types xy, polar, pie, bar and col are available. Available plot symbols are dot, star, plus, cross, ring and line. The plot type, the plot symbol and the X vector may be omitted. Then the following default values are used: xy, line and {1,2,...,n}. The plot types pie, bar and col can only be used with one data serie. For plot type xy the Y data series is plotted as a function of the X dataseries. For plot type polar the radia are given in X and the angles in Y.Every plot statement can take one, two or three additional string arguments.The additional arguments a, b and c are used as 1. axis label, 2.axis label and plot title.
Example : plot(xy,star,{1,2,3,4},{20,3,17,-4})
Example : plot(polar,line,{1,2,3,4},{20,3,17,-4})
Example : plot(bar,{20,3,17,-4})
Example : plot(xy,line,{1,2,3,4},{20,3,17,-4},"Time","Earnings","Results")

For statement
The statement list is repeated a number of times.
Syntax : for <variable> := <expression> to <expression> do <list of statements> next
Syntax : for <variable> := <expression> to <expression> step <expression> do <list of statements> next
Example : for a:=1 to 5 step 2 do a^2; a^3 next

While statement
The statement repeats a statement list until a condition is true. The condition must be an expression, which can be evaluated to true or false.
Syntax : while <boolean expression> do <list of statements> end
Example : a:=1: while a<4 do a^2; b:=a: a:=b+1: end

If statement
The if chooses between two statement lists depending upon a condition. The last statement list can be left out. The condition must be an expression, which can be evaluated to true or false.
Syntax : if <boolean expression> then <list of statements> else <list of statements> end
Syntax : if <boolean expression> then <list of statements> end
Example : if a>5 then b:=3 else c:=2 end

Keyword statement
A keyword statement consists of one word only.
who: Lists the environment, i.e. user-defined variables and functions.
restart: Clears the environment.
version: Prints system information.

Expression statement
The result is stored in variable <ans>
Syntax : <expression>
Example : 1+5

Expression statement with numbersystem
The result is stored in variable <ans>
Syntax : <expression> in bin|oct|dec|hex|roman
Syntax : <expression> in base n
Example : 1+5 in bin

Procedure definition statement
The list of statements are stored in the environment under the procedure name. The variables are used to initialize the environment when the procedure is executed.
Syntax : proc <procedure name>(<variable list>) := (local | global) <statement list> end
Example : proc g(a,b) := local a; b; a*b end

Procedure execution statement
The list of statements stored under the procedure name are executed. The values of the expressions are assigned to the variables listed as the procedure was defined. These values can be known to only the function (local) or be remembered when the procedure has executed (global). This must be set when the procedure is defined.
Syntax : do <procedure name>(<expression list>)
Example : do g(1,2)

Use semicolon or colon to separate multiple statements. Colon suppresses printing output, while semicolon allows for output to be printed. The last or only statement does not need a semicolon or a colon. When one is missing, a semicolon is assumed.
Example : 1+2; 2+3: 3+4

goto top
This free online symbolic calculator and solver enables you to define variables and functions as well as to evaluate expressions containing numbers in any number system from 2 (binary) over 8 (octal), 10 (decimal) and 16 (hexadecimal) to 36, roman numerals, complex numbers, intervals, variables, matrices, function calls, Boolean values (true and false) and operators (and, or, not ...), relations (e.g. greater than) and the if-then-else control structure. Comments are C-style /* */ or //. Plots are available using the plot statement.

Tell a friend - Share - About - Terms of use - Privacy policy - Contact - Impressum - FAQ - Member login
Version 0.3 release 6 Copyright © 1996-2008 by Tusanga. All rights reserved
Last updated: October 16, 2008