freeze
Create an inactive copy of a function
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.
freeze(f
)
freeze(f)
creates an inactive copy of the
function f
.
ff := freeze(f)
returns a function that is
an “inactive” copy of the argument f
.
This means:
ff
only evaluates its arguments,
but does not compute anything else,
ff
is printed in
the same way as f
,
symbolic ff
calls have the same type as symbolic f
calls,
if f
is a function
environment, then ff
has all the slots of f
.
ff
evaluates its incoming parameters even
if the function f
has the procedure option hold
.
Use freeze
when you want to perform many
operations with f
that require f
only
in its symbolic form, but f
need not be executed.
Neither eval
nor level
can
enforce the evaluation of an inactive function. See Example 2.
Create an inactive form of the function environment int
:
_int := freeze(int): F := _int(x*exp(x^2), x = 0..1)
The inactive form of int
keeps all information
that is known about the function int
, for example,
the output, the type, and the float
slot for floatingpoint
evaluation:
F, type(F), float(F)
The original function environment int
is not modified by freeze
:
int(x*exp(x^2), x = 0..1)
Use unfreeze
to reactivate the inactive function _int
and
evaluate the result:
unfreeze(F), unfreeze(F + 1/2)
This example shows the difference between hold
and freeze
. The
result of the command S := hold(sum)(...)
does
not contain an inactive version of sum
, but the unevaluated identifiersum
:
S := hold(sum)(1/n^2, n = 1..infinity)
The next time S
is evaluated, the identifier sum
is
replaced by its value, the function environmentsum
, and the procedure
computing the value of the infinite sum is invoked:
S
In contrast, evaluation of the result of freeze
does
not lead to an evaluation of the inactive function:
S := freeze(sum)(1/n^2, n = 1..infinity)
S
An inactive function does not react to eval
:
eval(S)
The only way to undo a freeze
is to use unfreeze
,
which reactivates the inactive function in S
and
then evaluates the result:
unfreeze(S)
freeze(f)
does not change the object f
,
but returns a copy of f
in an inactive form. This
means that computations with the inactive version of f
can
contain the original function f
.
For example, if you create an inactive version of the sine function:
Sin := freeze(sin):
and expand the term Sin(x+y)
, then the result
is expressed in terms of the original sine function sin
:
expand(Sin(x + y))

A procedure or a function environment 
An object of the same type as f
.