Sponsored links: Algebra eBooks
 

Help Index

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

R

S

T

U

V

W

X

Y

Z

The Maxima on-line user's manual

Algebra Calculator

Search:

Outermap Calculator

Outermap

Function: outermap (<f>, <a_1>, ..., <a_n>) Applies the function <f> to each one of the elements of the outer product <a_1> cross <a_2> ... cross <a_n>.

load (newton1);
eq1:sin(x)+cos(3*x)+1;
rng1:[-4,4];
subpart:8;
f1(x) := (if (x>=rng[1] and x<= rng[2]) then return(1) else return(2));
f1(3);
plot2d(eq1,[x,rng1[1],rng1[2]]);
li:makelist (i/subpart, i, rng1[1]*subpart, rng1[2]*subpart),numer;
sols:unique(map(round,flatten(sort(outermap(newton, [eq1], [x], li, [1E-6]))*1000))/1000),numer;

<f> is the name of a function of n arguments or a lambda expression of n arguments. Each argument <a_k> may be a list or nested list, or a matrix, or any other kind of expression.

The outermap return value is a nested structure. Let <x> be the return value. Then <x> has the same structure as the first list, nested list, or matrix argument, <x>[i_1]...[i_m] has the same structure as the second list, nested list, or matrix argument, <x>[i_1]...[i_m][j_1]...[j_n] has the same structure as the third list, nested list, or matrix argument, and so on, where <m>, <n>, ... are the numbers of indices required to access the elements of each argument (one for a list, two for a matrix, one or more for a nested list). Arguments which are not lists or matrices have no effect on the structure of the return value.

Note that the effect of outermap is different from that of applying <f> to each one of the elements of the outer product returned by cartesian_product. outermap preserves the structure of the arguments in the return value, while cartesian_product does not.

outermap evaluates its arguments.

See also map, maplist, and apply.

Examples:

Elementary examples of outermap. To show the argument combinations more clearly, F is left undefined.

          (%i1) outermap(F, [a, b, c], [1, 2, 3]);
          (%o1) [[F(a, 1), F(a, 2), F(a, 3)], [F(b, 1), F(b, 2), F(b, 3)],
                                               [F(c, 1), F(c, 2), F(c, 3)]]
          (%i2) outermap(F, matrix([a, b],[c, d]), matrix([1, 2],[3, 4]));
                   [ [ F(a, 1)  F(a, 2) ]  [ F(b, 1)  F(b, 2) ] ]
                   [ [                  ]  [                  ] ]
                   [ [ F(a, 3)  F(a, 4) ]  [ F(b, 3)  F(b, 4) ] ]
          (%o2)    [                                            ]
                   [ [ F(c, 1)  F(c, 2) ]  [ F(d, 1)  F(d, 2) ] ]
                   [ [                  ]  [                  ] ]
                   [ [ F(c, 3)  F(c, 4) ]  [ F(d, 3)  F(d, 4) ] ]
          (%i3) outermap (F, [a, b], x, matrix ([1, 2], [3, 4]));
                 [ F(a, x, 1)  F(a, x, 2) ]  [ F(b, x, 1)  F(b, x, 2) ]
          (%o3) [[                        ], [                        ]]
                 [ F(a, x, 3)  F(a, x, 4) ]  [ F(b, x, 3)  F(b, x, 4) ]
          (%i4) outermap (F, [a, b], matrix ([1, 2]), matrix ([x], [y]));
                 [ [ F(a, 1, x) ]  [ F(a, 2, x) ] ]
          (%o4) [[ [            ]  [            ] ],
                 [ [ F(a, 1, y) ]  [ F(a, 2, y) ] ]
                                        [ [ F(b, 1, x) ]  [ F(b, 2, x) ] ]
                                        [ [            ]  [            ] ]]
                                        [ [ F(b, 1, y) ]  [ F(b, 2, y) ] ]
          (%i5) outermap ("+", [a, b, c], [1, 2, 3]);
          (%o5) [[a + 1, a + 2, a + 3], [b + 1, b + 2, b + 3],
                                                     [c + 1, c + 2, c + 3]]

A closer examination of the outermap return value. The first, second, and third arguments are a matrix, a list, and a matrix, respectively. The return value is a matrix. Each element of that matrix is a list, and each element of each list is a matrix.

          (%i1) arg_1 :  matrix ([a, b], [c, d]);
                                      [ a  b ]
          (%o1)                       [      ]
                                      [ c  d ]
          (%i2) arg_2 : [11, 22];
          (%o2)                       [11, 22]
          (%i3) arg_3 : matrix ([xx, yy]);
          (%o3)                      [ xx  yy ]
          (%i4) xx_0 : outermap(lambda([x, y, z], x / y + z), arg_1,
                                                             arg_2, arg_3);
                         [  [      a        a  ]  [      a        a  ]  ]
                         [ [[ xx + --  yy + -- ], [ xx + --  yy + -- ]] ]
                         [  [      11       11 ]  [      22       22 ]  ]
          (%o4)  Col 1 = [                                              ]
                         [  [      c        c  ]  [      c        c  ]  ]
                         [ [[ xx + --  yy + -- ], [ xx + --  yy + -- ]] ]
                         [  [      11       11 ]  [      22       22 ]  ]
                           [  [      b        b  ]  [      b        b  ]  ]
                           [ [[ xx + --  yy + -- ], [ xx + --  yy + -- ]] ]
                           [  [      11       11 ]  [      22       22 ]  ]
                   Col 2 = [                                              ]
                           [  [      d        d  ]  [      d        d  ]  ]
                           [ [[ xx + --  yy + -- ], [ xx + --  yy + -- ]] ]
                           [  [      11       11 ]  [      22       22 ]  ]
          (%i5) xx_1 : xx_0 [1][1];
                     [      a        a  ]  [      a        a  ]
          (%o5)     [[ xx + --  yy + -- ], [ xx + --  yy + -- ]]
                     [      11       11 ]  [      22       22 ]
          (%i6) xx_2 : xx_0 [1][1] [1];
                                [      a        a  ]
          (%o6)                 [ xx + --  yy + -- ]
                                [      11       11 ]
          (%i7) xx_3 : xx_0 [1][1] [1] [1][1];
                                            a
          (%o7)                        xx + --
                                            11
          (%i8) [op (arg_1), op (arg_2), op (arg_3)];
          (%o8)                  [matrix, [, matrix]
          (%i9) [op (xx_0), op (xx_1), op (xx_2)];
          (%o9)                  [matrix, [, matrix]

outermap preserves the structure of the arguments in the return value, while cartesian_product does not.

          (%i1) outermap (F, [a, b, c], [1, 2, 3]);
          (%o1) [[F(a, 1), F(a, 2), F(a, 3)], [F(b, 1), F(b, 2), F(b, 3)],
                                               [F(c, 1), F(c, 2), F(c, 3)]]
          (%i2) setify (flatten (%));
          (%o2) {F(a, 1), F(a, 2), F(a, 3), F(b, 1), F(b, 2), F(b, 3),
                                                 F(c, 1), F(c, 2), F(c, 3)}
          (%i3) map(lambda([L], apply(F, L)),
                               cartesian_product({a, b, c}, {1, 2, 3}));
          (%o3) {F(a, 1), F(a, 2), F(a, 3), F(b, 1), F(b, 2), F(b, 3),
                                                 F(c, 1), F(c, 2), F(c, 3)}
          (%i4) is (equal (%, %th (2)));
          (%o4)                         true

(%o1)                                true
(%i2) 

Outermap Example

Related Examples

outermap

outermap("*",[a,b,c],...

Calculate

outermap

outermap("*",[a,b,c],...

Calculate

outermap

a:[.02778,.05556,.083...

b:[.02778,.08333,.166...

c: outermap("+",b,a);

Calculate

outermap

a:[.02778,.05556,.083...

b:[.02778,.08333,.166...

c: outermap("+",b,a);

Calculate

outermap

a:[.02778,.05556,.083...

b:[.02778,.08333,.166...

c: outermap("+",b,a);

Calculate

outermap

a:[2.8,5.6,8.3];

b:[2.8,8.3,16.7];

c: outermap("+",a,b);

Calculate

outermap-transpose

a:[.02778,.05556,.083...

b:[.02778,.08333,.166...

c: outermap("+",a,b);

Calculate

outermap

outermap("*",[a,b,c],...

Calculate

outermap

a:[2.8,5.6,8.3];

b:[2.8,8.3,16.7];

c: outermap("+",a,b);

Calculate

outermap

a:[2.8,5.6,8.3];

b:[2.8,8.3,16.7];

c: outermap("+",a,b);

Calculate