' ----------- VECTOR OPERATIONS ---------------- LCD.Clear() LCD.Text(1, 0,0, 1,"Vector operations") A = Vector.Init(5, 0) ' create vector with 5 elements 0 A[0] = 13 ' add some data A[1] = -8 ' add some data A[4] = 4 ' add some data LCD.Text(1, 0,24,0, "A: ") For i=0 To 4 LCD.Text(1, 30+20*i,24, 1, A[i]) EndFor ' add 7 to every element of V and store in X B = Vector.Init(5, 7) ' create a vector with all 7s LCD.Text(1, 0,36, 1," + ") For i=0 To 4 LCD.Text(1, 30+20*i,36, 1, B[i]) EndFor ' add these two vectors number-wise X = Vector.Add(5, A,B) LCD.Text(1, 0,48, 1,"X: ") For i=0 To 4 LCD.Text(1, 30+20*i,48, 1, X[i]) EndFor ' compute the scalar product of A and X and store in vector Y ' (it is allowed to use same array as source and destination of operations) Y = A Y = Vector.Multiply(1,1,5, Y,X) LCD.Text(1, 10,72, 1,"scalar A*X: "+Y[0]) Buttons.Flush() Buttons.Wait() ' ---------- MATRIX MULTIPLICATION ---------- LCD.Clear() LCD.Text(1,0,0, 1,"Multiply") LCD.Text(1,0,10, 1,"matrizes") N = 4 M = 3 K = 2 ' Define a 4 row, 2 column matrix. A = Vector.Init(4*2,0) A[2*0+0] = 2 A[2*0+1] = -1 A[2*1+0] = 1 A[2*1+1] = 3 A[2*2+0] = 1 A[2*2+1] = 2 A[2*3+0] = -3 A[2*3+1] = 1 For I=0 To N-1 For H=0 To K-1 LCD.Text(1, 10+30*H,60+12*I, 1, A[K*I+H]) EndFor EndFor ' Define a 2 rows, 3 column matrix. B = Vector.Init(2*3,0) B[3*0+0] = 3 B[3*0+1] = -1 B[3*0+2] = 4 B[3*1+0] = 3 B[3*1+1] = 2 B[3*1+2] = -2 For H=0 To K-1 For J=0 To M-1 LCD.Text(1, 80+30*J,20+12*H, 1, B[M*H+J]) EndFor EndFor ' The resulting matrix will have 4 rows, 3 columns. C = Vector.Multiply(N,M,K, A,B) For I=0 To N-1 For J=0 To M-1 LCD.Text(1, 80+30*J,60+12*I, 1, C[M*I+J]) EndFor EndFor Buttons.Flush() Buttons.Wait() ' ----------------- SORT VECTOR ------------- LCD.Clear() LCD.Text(1,0,0,1, "Sort 60 numbers") X = Vector.Init(57,0) For I=0 To 57-1 X[i] = Math.GetRandomNumber(1099)-99 ' -99 - 999 EndFor ' Sort 60 elements. Since there are too few numbers in X, 0-values will be inserted. Y = Vector.Sort(60,X) For I=0 To 12-1 For j=0 To 5-1 LCD.Text(1, 36*j, 9+10*i, 1, Y[i*5+j]) endfor EndFor Buttons.Flush() Buttons.Wait()