12.07.2015 Views

Learning Guide Learning Guide

Learning Guide Learning Guide

Learning Guide Learning Guide

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

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

5.3 Structural Manipulations • 171You can also use the seq command to generate sequences resemblingthe output from map. In this example, seq generates a sequence by applyingthe function f to the elements of a set and a list.> seq( f(i), i={a,b,c} );f(a), f(b), f(c)> seq( f(p, i, q, r), i=[a,b,c] );f(p, a, q, r), f(p, b, q, r), f(p, c, q, r)Another example is Pascal’s Triangle.> L := [ seq( i, i=0..5 ) ];L := [0, 1, 2, 3, 4, 5]> [ seq( [ seq( binomial(n,m), m=L ) ], n=L ) ];[[1, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0],[1, 3, 3, 1, 0, 0], [1, 4, 6, 4, 1, 0], [1, 5, 10, 10, 5, 1]]> map( print, % );[1, 0, 0, 0, 0, 0][1, 1, 0, 0, 0, 0][1, 2, 1, 0, 0, 0][1, 3, 3, 1, 0, 0][1, 4, 6, 4, 1, 0][1, 5, 10, 10, 5, 1][]The add and mul commands work like seq except that they generatesums and products, respectively, instead of sequences.> add( i^2, i=[5, y, sin(x), -5] );

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

Saved successfully!

Ooh no, something went wrong!