Formules: Fonctions non numériques
De MoodleDocs
Remarque : la traduction de cette page n'est pas terminée. N'hésitez pas à traduire tout ou partie de cette page ou à la compléter. Vous pouvez aussi utiliser la page de discussion pour vos recommandations et suggestions d'améliorations.
Fonctions non numériques
Fonction | Exemples | Resultat | Description |
---|---|---|---|
concat(X1,X2, ...) | concat([1],[2,3],[4]) | [1,2,3,4] | Returns a list by concatenating X1, X2, ... |
concat(["A"],["B"]) | ["A","B"] | ||
diff(X,Y) diff(X,Y,N) |
diff([1,1,1],[1,4,9]) | [0,3,8] | Return a list of number D of difference between the list X and Y element wise. If X and Y are a list of number, then D[i] will be abs(X[i]-Y[i]). If X and Y are a list of string, then D[i] will be the difference between the algebraic formula X[i] and Y[i]. |
diff(["x*x"],["x^2"]) | [0] | ||
diff(["x"],["x^2"],20) | A list with number >= 0 | ||
fill(N,value) | fill(3,0) | [0,0,0] | Returns a list with size N and all elements filled by value. |
inv(X) | inv([0,3,1,2]) | [0,2,3,1] | Return the inverse permutation of X, which is the same as R in for(i:[0:N]) R[X[i]]=i with size N of X. It has the property that X==inv(inv(X)) and A==sublist(sublist(A,X),inv(X)). |
join(s,A,B...) | join(" ",["Hello","world"]) | "Hello world" | Returns a string that joins all elements together and separated by string s . The A, B, ... can be any number or string or list. |
join("",1,"+",2,["="]) | "1+2=" | ||
len(X) | len([0:10]) | 10 | Returns the length of the list X |
map(uop,X) map(bop,X,Y) |
map("abs",[-1,2,-3]) | [1,2,3] | Returns a list by applying the operator/function element wise to all elements in X. The uop or bop are the string of unary or binary operators (or functions) for numbers respectively. |
map("+",[1,2,3],5) | [6,7,8] | ||
map("<",[3,4],[1,7]) | [0,1] | ||
pick(i,X) pick(i,x0,x1,...) |
pick(1<2,["A","B"]) | "B" | A safe variant of list subscript. It picks the i-th element from the list X or the first element if index out of range. pick(i,x0,x1,...) picks the i-th element in the [x0,x1,...] , or x0 if index out of range. |
pick(10,"","A","B") | "" | ||
pick(1,[1,2],[3,4]) | [3,4] | ||
sort(X) sort(X,Y) |
sort(["B","C","A"]) | ["A","B","C"] | Returns the sorted list of X in ascending order. sort(X,Y) sortd the list X,Y together by sorting Y in ascending order and returns the sorted list X. |
sort(["B","C","A"],[0,2,1]) | ["B","A","C"] | ||
str(x) | str(1.1) | "1.1" | Converts the number x into a string |
sublist(X,Y) | sublist([7,8,9],[1,1,2]) | [8,8,9] | Returns a sublist R of X using list Y as index, where R[i] = X[Y[i]]. If Y is a permutation, say Y=shuffle([0:5]), then X is permuted depending on Y sum(X). |
sublist([7,8,9],[2,1,0]) | [9,8,7] | ||
sum(X) | sum([1,2,3]) | 6 | Returns the sum of all elements in the list of numbers X |