## `assign` -- perform assignments given as equations

#### Introduction

For each equation in a list, a set, or a table of equations `L`, `assign(`L`)` evaluates both sides of the equation and assigns the evaluated right hand side to the evaluated left hand side.

`assign(`L, S`)` does the same, but only for those equations whose left hand side is in the set `S`.

#### Call(s)

`assign(L)`
`assign(L, S)`

#### Parameters

`L` | - | a list, a set, or a table of equations
`S` | - | a set

#### Returns

`L`.

#### Related Functions

`:=`, `_assign`, `assignElements`, `delete`, `evalassign`

#### Details

- Since the arguments of `assign` are evaluated, the evaluation of the left hand side of each equation in `L` must be an admissible left hand side for an assignment. See the help page of the assignment operator `:=` for details.

- Several assignments are performed from left to right. See example 4.
- `assign` can be conveniently used after a call to `solve` to assign a particular solution of a system of equations to the unknowns. See example 5.

#### Example 1

We assign values to the three identifiers `B1,B2,B3`:

    >> delete B1, B2, B3:
       assign([B1 = 42, B2 = 13, B3 = 666]): B1, B2, B3

                                    42, 13, 666

We specify a second argument to carry out only those assignments with left hand side `B1`:

    >> delete B1, B2, B3:
       assign([B1 = 42, B2 = 13, B3 = 666], {B1}): B1, B2, B3

                                    42, B2, B3

The first argument may also be a table of equations:

    >> delete B1, B2, B3:
       assign(table(B1 = 42, B2 = 13, B3 = 666)): B1, B2, B3

                                    42, 13, 666

#### Example 2

Unlike `_assign`, `assign` evaluates the left hand sides:

    >> delete a, b: a := b: assign({a = 3}): a, b

                                       3, 3

    >> delete a, b: a := b: a := 3: a, b

                                       3, b

#### Example 3

The object assigned may also be a sequence:

    >> assign([X=(2,7)])

                                   [X = (2, 7)]

    >> X

                                       2, 7

#### Example 4

The assignments are carried out one after another, from left to right. Since the right hand side is evaluated, the identifier `C` gets the value `3` in the following example:

    >> assign([B=3, C=B])

                                  [B = 3, C = B]

    >> level(C,1)

                                         3

#### Example 5

When called for an algebraic system, `solve` often returns a set of lists of assignments. `assign` can then be used to assign the solutions to the variables of the system:

    >> sys:={x^2+y^2=2, x+y=5}:
       S:= solve(sys)

                              1/2              1/2
          {[x = 5/2 - 1/2 I 21   , y = 1/2 I 21    + 5/2],

                          1/2                          1/2
             [x = 1/2 I 21    + 5/2, y = 5/2 - 1/2 I 21   ]}

We want to check whether the first solution is really a solution:

    >> assign(S[1]): sys

                                    1/2 2            1/2       2
             {5 = 5, (5/2 - 1/2 I 21   )  + (1/2 I 21    + 5/2)  = 2}

Things become clearer if we use floating point evaluation:

    >> float(sys)

                     {5.0 = 5.0, 2.0 - 8.67361738e-19 I = 2.0}

#### Changes

- no changes

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000