11.07.2015 Views

Maple 9 Learning Guide - Maplesoft

Maple 9 Learning Guide - Maplesoft

Maple 9 Learning Guide - Maplesoft

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

f := (x, y) → is(x < y)6.3 Structural Manipulations • 187> sort( [4.3, Pi, 2/3, sin(5)], bf );[sin(5), 2 , π, 4.3]3You can also sort strings by length.> shorter := (x,y) -> evalb( length(x) < length(y) );shorter := (x, y) → evalb(length(x) < length(y))> sort( ["Mary", "has", "a", "little", "lamb"], shorter );[“a”, “has”, “lamb”, “Mary”, “little”]Sorting Mixed List of Strings and Numbers <strong>Maple</strong> does not have abuilt-in method for sorting lists of mixed strings and numbers, other thanby machine address. To sort a mixed list of strings and numbers, you cando the following.> big_list := [1,"d",3,5,2,"a","c","b",9];big_list := [1, “d”, 3, 5, 2, “a”, “c”, “b”, 9]Make two lists from the original, one consisting of numbers and oneconsisting of strings.> list1 := select( type, big_list, string );list1 := [“d”, “a”, “c”, “b”]> list2 := select( type, big_list, numeric );list2 := [1, 3, 5, 2, 9]Then sort the two lists independently.> list1 := sort(list1);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!