Lists

SpeQ supports lists of values. You can not only do calculation with single values, but also with multiple values at the same time.
(3.4, 20.1, 5.6) * 3
       Ans = (10.2, 60.3, 16.8)

Sqrt(2, 3, 9)
       Ans = (1.414213562, 1.732050808, 3)
Lists are for example usefull when using statistical functions like Min, Max, Sum, Avg, Sort, etc. Instead of entering for example
Sum(2.0, 3.1, 5.3)
       Ans = 10.4
you can create a variable myList which contains the three values, and use that variable to calculate the sum. Once the list is created, you can easily use it in other calculations, for example for calculating the average value of the values also.
myList = (2.0, 3.1, 5.3)
       myList = (2.0, 3.1, 5.3)

Sum(myList)
       Ans = 10.4

Avg(myList)
       Ans = 3.466666667
When you have defined a variable that contains a list of values, you can get and adjust the values of specific elements in the list.
a = (5.4, 2.1, 8.8 - 1)
       a = (5.4, 2.1, 7.8)

a(1)
       Ans = 5.4
a(2, 3)
       Ans = (2.1, 7.8)

a(1) = 10.2
       a = (10.2, 2.1, 7.8)
a(2, 3) = (3.0, 9.1)
       a = (10.2, 3, 9.1)


Back to top

Examples

' Examples of using Lists

' You can do calculations for multiple values simultaneously
(2.1, 9.0) + (3.4, 9)
       Ans = (5.5, 18)
Sqrt(9, 25, 36, 49)
       Ans = (3, 5, 6, 7)

' when you need to calculate the sum and average of
' the values 2.3, 5.1, -1.3 and 7.2 you can do it like this:

Sum(2.3, 5.1, -1.3, 7.2)
       Ans = 13.3

Avg(2.3, 5.1, -1.3, 7.2)
       Ans = 3.325

' when you need the same list of values multiple times,
' it is usefull to create a variable for it
myList = (2.3, 5.1, -1.3, 7.2)
       myList = (2.3, 5.1, -1.3, 7.2)

' You can use this defined list in further calculations
Sum(myList)
       Ans = 13.3

Avg(myList)
       Ans = 3.325

Std(myList)
       Ans = 3.679107682

' With the function sort you can sort the values in a list
Sort(myList)
       Ans = (-1.3, 2.3, 5.1, 7.2)


' You can do all kind of calculations with lists
a = (5.4, 2.1, 8.8 - 1)
       a = (5.4, 2.1, 7.8)
b = (1, 2, 3)
       b = (1, 2, 3)
c = (a, b)
       c = (5.4, 2.1, 7.8, 1, 2, 3)

a + b
       Ans = (6.4, 4.1, 10.8)
a - b
       Ans = (4.4, 0.1, 4.8)
a * 3
       Ans = (16.2, 6.3, 23.4)
b / 2
       Ans = (0.5, 1, 1.5)


' You can get specific elements from a list
' get the third element from the list c
c(3)
       Ans = 7.8
' get the third, fourth and fifth element from the list c
c(3, 4, 5)
       Ans = (7.8, 1, 2)

'get the third and first element from the list a
a(3, 1)
       Ans = (7.8, 5.4)

' you can also change the value of specific elements in a list
' change the second element in b
b(2) = 4
       b = (1, 4, 3)

' change the first and third element from a
a(1, 3) = (1.1, 9.0)
       a = (1.1, 2.1, 9)

' combine two lists
d = (a, b)
       d = (1.1, 2.1, 9, 1, 4, 3)

' It is possible to create a function that returns a list
' create a function to calculate a multiplication table
table(x) = (1*x, 2*x, 3*x, 4*x, 5*x, 5*x, 7*x, 8*x, 9*x, 10*x)
       Function table(x) is defined

' Now get the multiplication table of three
table(3)
       Ans = (3, 6, 9, 12, 15, 15, 21, 24, 27, 30)

' And the multiplication table of seven
table(7)
       Ans = (7, 14, 21, 28, 35, 35, 49, 56, 63, 70)
Back to top

See Also

Expressions, Statistic Functions