Numbers (including complex numbers), numeric arrays, strings, structs (dictionaries/maps), and cells (arrays of elements which are not necessary of the same type) are the basic data types in Mathnium. Mathnium also has a facility for the definition of derived data types as classes, which are similar to Java classes, except that all fields and methods in a class have public access. The arrays may have arbitrary number of dimensions.
Numeric data types include the following:
1, 7,-8 which are, for all practical purposes, the 32 bit integers.C, i.e., nonzero integers are treated as true in boolean valued expressions, and zero represents false.1.4, 3.1726, 1.2e30 which are, for all practical purposes, the 64 bit doubles.Complex numbers, such as 1.4+i*2.1, 3.1726+j_23, 1.2+i_4, 2.36+8.9_j, -8.23-7.67_i which are defined as the sum of real and imaginary parts, both of them being 64 bit doubles, with imaginary parts defined
by using j_, i_ as prefix or _j, _i as suffix.
The imaginary part may also be defined by multiplying a double by i, but this may not be convenient in many cases, since, habitually, most programmers tend to redfine the value of the variable i.
>>a=[ 2 3 4; 6 7 8] // a 2X3 matrix
>>a=[ 10 pi ; sin(pi/3) 7 ] // a 2X2 matrix
>>a=[ 10 -pi 2+3_j ; cos(pi/3) 7 j_8; -10 2 9 ] // a 3X3 complex matrix
>>a=[ 5 10 13
12 16 18] // a 2 X 3 matrix
As shown above, a matrix is defined by specifying its elements within
square brackets, with each row separated by the new line character or a semi-colon.
>>a[1:2,1:2,3]=[2 3 ; 4 5]
>>a[1:2,1:2,2]=[5 6; 7 8]
>>a
[:,1:2, 1]
0 0
0 0
[:,1:2, 2]
5 6
7 8
[:,1:2, 3]
2 3
4 5
>>a[1:2,1:2,1]=[10, 12; 15 16]
>>a
[:,1:2, 1]
10 12
15 16
[:,1:2, 2]
5 6
7 8
[:,1:2, 3]
2 3
4 5
addition (+)
operator is used with strings, the double quoted strings are concatenated,
whereas the single quoted strings (character arrays) are treated as one dimensional numeric arrays
in this context.
>>a="Java "
>>b="Programs"
>>a+b
Java Programs
>>c='Java '
>>d='Programs '
>>c+d
Error Invalid operand sizes for matrix addition/subtraction
in \Main
>>c='Java '
>>c+d
Columns 1 through 6
154 211 229 200 146 129
Columns 7 through 9
141 147 64
Apart from this distinction, both the forms of strings behave as
character (numeric) arrays
when used as operands for arithmetic, logical or ralational operators.
. notation for the keys.
>>a=struct("x",2,"y",'value',"z",rand(2,3)) // construct a struct with 3 fields
>>a
x: 2
z: 2X3 Real Matrix
y: value
>>a.x // accesing the fields of a struct
2
>>a.y
value
>>a.z
0.1192 0.2547 0.4838
0.7092 0.5313 0.9464
>>a.w=3 // Another way to define a field of a 'struct'
>>a
x: 2
w: 3
z: 2X3 Real Matrix
y: value
>>// A 2 X 3 array of cells.
>>a={2, 3, "Program"; rand(3,2), "Computer", struct("x",2,"y",3)}
>>a
[2] [3] [Program]
[3X2 Real Matrix] [Computer] [1X1 Struct Array]
>>a{1,1} // accessing the elements
2
>>a[1,2] // For accessing the elements, square brackets may also be used.
3
>>a[2,1]
0.8778 0.7014
0.0349 0.5651
0.6343 0.9999
>>a[2,3]
x: 2
y: 3
>>a{2,3}
x: 2
y: 3
Multi-dimenional cell arrays may also be defined as usual.
>>a{1,2,2}=10
>>a{2,2,2}="Arrays"
>>a
[:, :, 1]
[2] [3] [Program]
[3X2 Real Matrix] [Computer] [1X1 Struct Array]
[:, :, 2]
[null] [10] [null]
[null] [Arrays] [null]
>>a{1,1,2}=rand(2,2)+j_rand(2,2)
>>a
[:, :, 1]
[2] [3] [Program]
[3X2 Real Matrix] [Computer] [1X1 Struct Array]
[:, :, 2]
[2X2 Complex Matrix] [10] [null]
[null] [Arrays] [null]
>>a[1,1,2]
0.9743 + 0.8799i 0.3372 + 0.045i
0.1712 + 0.8715i 0.2501 + 0.134i
>>Vector.class
class java.util.vector
>>Hashtable.class
class java.util.hashtable
>>a=new Vector()
>>a.add(10)
1
>>a.add("Java Vector")
1
>>a.add(rand(2,3))
1
>>a
[10, Java Vector, [[D@1d225a7]
>>a[1]
10
>>a[2]
Java Vector
>>a[3]
0.1796 0.2813 0.0273
0.8685 0.0048 0.2866
>>b=new Hashtable()
>>b.put("x",10)
>>b.put("y",[2 3; 4 5])
>>b.put("z",{1,"A string";10,[3 4]})
>>b
{x=10, z=[2X3 Cell], y=[[D@6ac461}
>>b.x
10
>>b.y
2 3
4 5
>>b.z
[1] [A string]
[10] [1X2 Integer Matrix]
>>b.z{1,1}
1
>>b.z{1,2}
A string
>>b.z{2,2}
3 4