This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Perform assignments given as equations

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


assign(L, S)


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.

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

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

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

Example 2

Unlike _assign, assign evaluates the left hand sides:

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

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

Example 3

The object assigned may also be a sequence:



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])


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)

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

assign(S[1]): sys

Things become clearer if we use floating-point evaluation:




A list, a set, or a table of equations


A set

Return Values


See Also

MuPAD Functions

Was this topic helpful?