# assign

Tags:

Updated:

assign is used to explicitly assigning the value obtained when applying the command value on an sdpvar object. YALMIP typically assigns values after solving problem, but a manual use of the command is to define initial guesses for warm-starting when solvers support these.

Note, assign does not replace replace or constrain the variable with a particular value. It is only used for initial values in nonlinear solvers. Hence, only used when the option usex0 in sdpsettings is activated.

### Syntax

assign(X,Y)


### Examples

Variables are initialized as NaN by default

x = sdpvar(1,1);
value(x)

ans =
NaN


By using assign, the current value can be altered

assign(x,1)
value(x)

ans =
1


By default, inconsistent assignments generate an error message.

t = sdpvar(1,1);x = [t t];
assign(x,[1 2])
??? Error using ==> sdpvar/assign
Inconsistent assignment


With a third argument, a least squares assignment is obtained

t = sdpvar(1,1);x = [t t];
assign(x,[1 2],1)
value(x)

ans =

1.5000    1.5000


The value can be used as an initial guess in warm-starts for solvers supporting this

x = sdpvar(1,1);
assign(x,pi);
optimize([sin(x)^2 <= .1],x,sdpsettings('usex0',1));