Assigning values

### 4.6.2 Assigning values

You can assign a value to a variable with the := operator. For example, to give the variable a the value of 4, you can enter

a := 4

Alternatively, you can use the => operator; when you use this operator, the value comes before the variable;

4 => a

The function sto or Store can also be used; again, the value comes before the variable

sto(4,a)

After any one of these commands, any time you use the variable a in an expression, it will be replaced by 4.

You can use sequences or lists to make multiple assignments at the same time. For example,

(a,b,c) := (1,2,3)

will assign a the value 1, b the value 2 and c the value 3. Note that this can be used to switch the values of two variables; with a and b as above, the command

(a,b) := (b,a)

will set a equal to b’s original value, namely 2, and will set b equal to a’s original value, namely 1.

Another way to assign values to variables, useful in Maple mode, is with the assign. If you enter

assign(a,3)

or

assign(a = 3)

then a will have the value 3. You can assign multiple values at once; if you enter

assign([a = 1, b = 2])

then a will have the value 1 and b will have the value 2. This command can be useful in Maple mode, where solutions of equations are returned as equations. For example, if you enter (in Maple mode)

sol := solve([x + y = 1, y = 2])

you will get

[x = -1, y = 2]

If you then enter

assign(sol)

the variable x will have value -1 and y will have the value 2. This same effect can be achieved in standard Xcas mode, where

sol := solve([x + y = 1, y = 2])

will return

[[x = -1, y = 2]]

In this case, the command

[x,y] := sol[0]

will assign x the value -1 and y the value 2.