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.
If you rely on correctness of particular statements for your code, then consider including these statements in the code. Such statements are called assertions. Assertions help you remember specific conditions under which you expected to execute your code. They can also help other developers who might need to review or update your code.
MuPAD® lets you use checked assertions.
If you switch to a special mode of executing your code, the system
evaluates assertions during run time. If an assertion does not evaluate
the system stops code execution and throws an error.
For example, this procedure solves the equation sin(x)
+ cos(x) = a2.
Suppose you get the parameter
a as a result of
some computations, and you expect the condition to
be always valid. Relying on this condition, you expect the solutions
to be real. Specify this condition as an assertion by using
f := proc(a) begin assert(a^2 <= sqrt(2)); s := solve(sin(x) + cos(x) = a^2) end:
Assertions are checked only when you run your code in a special mode called the argument checking mode. Otherwise, the system ignores all assertions. For example, in this procedure call, MuPAD skips the assertion and returns the following complex result:
Now when you call the procedure
f, MuPAD checks
the assertion. For
a = 4/3, the assertion
and the procedure execution stops with the error:
Error: Assertion 'a^2 <= sqrt(2)' has failed. [f]
a = 1, the assertion evaluates
The procedure call runs to completion, and returns the following set
of real solutions: