Mate - online symbolic calculator by Tusanga


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

Calculation / Getting started

This page is meant as a first introduction to the system. For more detail please consult the expressions, statements, functions, examples and questions pages.

The user can assign values to variables.

Input:
a := 2

Output:
a := 2


The first line "a := 2" is the user input. The second line is the output from the system. In this case the system reponds, that it has assigned the variable a the value 2.
Let's see the system perform calculations.

Input:
b := 3 + 4

Output:
b := 7


The right hand side of a variable assignment statement can include known variables

Input:
a := 2 ; b := 7 ; c := a + b

Output:
a := 2

Output:
b := 7

Output:
c := 9


... or unknown variables

Input:
d := 2 + q + 4

Output:
d := 6 + q


Let's list all the defined variables using the command who

Input:
a := 2; b := 7 ; who

Output:
a := 2

Output:
b := 7

Output:
Mate's environment:

Output:
a := 2

Output:
b := 7


Besides the variable assignment statement there are other types of statements. One example is the expression statement. It just consists of an expression to calculate.

Input:
2 * 27

Output:
54


The system can also return integer results in the binary, octal or hexadecimal number system. Use in bin for binary output. Replace with oct and hex for octal and hexadecimal output.

Input:
2 * 27 in hex

Output:
0x36


The result of an expression statement is always stored in the variables ans. This way the result can be used in following statements.

Input:
2 - 7 ; 2 * ans

Output:
-5

Output:
-10


To separate multiple statements one can use a colon or a semicolon. The colon suppresses output of the preceeding statement. If the last or the only statement omits the colon as well as the semicolon, a semicolon is assumed and the result is printed.

Input:
2 ^ 4 ; 3 * 4: 5 - 6

Output:
16

Output:
-1


Let's define a function on one variable and use it.

Input:
f(x) := 2 * x ^ 2 ; f(3)

Output:
f (x) := (2*(x^2))

Output:
18


Functions on more than one variables can also be defined.

Input:
g(x,y,z) := x + y + 2 * z : g(1, 2, 3)

Output:
9


We can use floating point numbers, numbers in the binary or hexadecimal system or even roman numerals.

Input:
2.5-1.8 ; 0b1101 ; 0h2f ; MCMLXXIV|r

Output:
0.7

Output:
13

Output:
47

Output:
1974


In fact, we can use any number system from 2 to 36. Let's see what 27 is in a number system with base 9. We check the result by also calculating it directly.

Input:
327|9; ans == (3*9^2+2*9+7)

Output:
268

Output:
true


Vectors and matrices are also facilitated for. We'll define a matrix and a vector and multiply them. The two elements of the resulting vector is then assigned to two different scalar variables.

Input:
M := { 1, 2 ; 3, 4 } : v := { 5,6 }` : w := M * v ; {k1,k2}:=w`

Output:
w := {17 ; 39}

Output:
k1 := 17

Output:
k2 := 39


If v is unknown and w known, we can solve the linear system of equations M * v = w using the solvem function. We'll compare the result to the known value of v to make sure the result is correct.

Input:
M := { 1, 2 ; 3, 4 } : w := {17 ; 39}: {v,H} := solvem(M,w); v == { 5,6 }`

Output:
v := {5 ; 6}

Output:
H := 0

Output:
true

That H equals 0 indicate that we have found an exact solution.

We extend the system to become over-determined. M has become a third row. We calculate w := M*v. Calling the function solvem(M,w) would give us the original v. Instead we change w a little to make it over-determined and then solve for v. Because the system is over-determined we get a least square solution. This is indicated by H being NaN. Notice how the original v and the solution v2 to the over-determined system differ. Mate tries to keep integers and fractions as far as possible. To convert the result to floating points we use the function float.

Input:
M := { 1, 2 ; 3, 4 ; 2, 3 } : v := { 5,6 }`: w := M*v; w2:=w+{0,0,1}`; {v2,H} := solvem(M,w2); v2 <> v; v2-v; float(ans)

Output:
w := {17 ; 39 ; 28}

Output:
w := {17 ; 39 ; 29}

Output:
v2 := {(14/3) ; (19/3)}

Output:
H := NaN

Output:
true

Output:
{(-1/3) ; (1/3)}

Output:
{-0.333333333333 ; 0.333333333333}


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