Evaluate at a Point

MuPAD® notebooks will be removed in a future release. 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.

To evaluate an expression for particular values of identifiers, use the evalAt function or its shortcut |. For example, evaluate the following expression at the point x = 0:

diff(x^2*exp(sin(x)), x $ 3) | x = 0

In MuPAD®, all computations are symbolic by default. For example, evaluating the previous expression at x = 1 returns the exact symbolic result:

diff(x^2*exp(sin(x)), x $ 3) | x = 1

To get a numeric approximation of the result, use the floating-point number to specify the point at which you want to evaluate an expression:

diff(x^2*exp(sin(x)), x $ 3) | x = 1.0

Alternatively, you can evaluate an expression at a point by using the subs function with the EvalChanges option. For expressions that contain only free variables, evalAt and subs return identical results:

diff(sin(x)*cos(x^2), x $ 2) | x = PI,
subs(diff(sin(x)*cos(x^2), x $ 2), x = PI, EvalChanges)

evalAt and subs return different results for the expressions that contain dependent variables. The subs function does not distinguish between free and dependent variables. The function replaces both free and dependent variables with the new value, for example:

subs(x + int(f(x), x = 0..infinity), x = 1)

The evalAt function replaces only free variables:

x + int(f(x), x = 0..infinity) | x = 1