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.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

**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.**

Suppose you want to verify the solutions of this polynomial equation:

equation := x^3 + 4 = 0: solution := solve(equation)

To verify the correctness of the returned solutions, substitute
the solutions into the original equation. To substitute the results
given in the form of equations, evaluate the original equations at
the solution points. Use `evalAt`

or the vertical bar `|`

as
a shortcut. For the first solution, the command returns the identity:

equation | solution[1]

To check that the left side of the equation is equal to the
right side, use the `testeq`

command:

testeq(equation | solution[1])

For the second solution, `evalAt`

returns an equation with an unsimplified
left side. In many cases, MuPAD^{®} does not automatically simplify
expressions, for example:

equation | solution[2];

`testeq`

simplifies
the expressions on both sides of the equation:

testeq(equation | solution[2])

As an alternative to evaluating at a point, use the `subs`

command to substitute
the solution into the original equation:

equation := x^3 + 4 = 0: solution := solve(equation); testeq(subs(equation, solution[1])); testeq(subs(equation, solution[2])); testeq(subs(equation, solution[3]))

To verify the solutions of a system of equations, test each equation separately:

equations := {x^2 + 2*y = 3, 4*x^2 + 5*y = 6}: solutions := solve(equations, {x, y}); testeq((equations|solutions[1])[1]); testeq((equations|solutions[1])[2]); testeq((equations|solutions[2])[1]); testeq((equations|solutions[2])[2])

Suppose you want to verify the solutions of this trigonometric equation:

equation := sin(x)/x = 0: solution := solve(equation, x)

To verify the results, evaluate the original equation at the
solution points. Evaluating at a point requires a solution to be in
the form of an equation. If you have a solution in the form of membership, `evalAt`

returns
an error:

equation | op(solution)

Error: An equation is expected.

You cannot use the expression `x = solution`

directly
because `solution`

is represented by a set. This
set contains the solution for the variable `x`

, the
independent variable `k`

, and the condition on the
variable `k`

:

op(solution)

Extract the solution for `x`

, the variable `k`

,
and the conditions on the variable `k`

from the set. MuPAD returns
the variable `k`

and its conditions as lists. Use
the additional square brackets to extract `k`

and
the conditions from the lists:

op(solution)[1]; op(solution)[2][1]; op(solution)[3][1]

Now evaluate the original equation at the solution points * x =
π k* under the
conditions for

`k`

:testeq(equation | x = op(solution)[1]) assuming op(solution)[2][1] in op(solution)[3][1]

Alternatively, use the `subs`

command
to substitute the solution into the original equation:

testeq(subs(equation, x = op(solution)[1])) assuming op(solution)[2][1] in op(solution)[3][1]

`IgnoreAnalyticConstraints`

If you verify solutions of an equation or a system solved with
the `IgnoreAnalyticConstraints`

option, `testeq`

can return `FALSE`

or `UNKNOWN`

,
for example:

equation := ln(x) + ln(x + 10) = ln(y): solutions := solve(equation, x, IgnoreAnalyticConstraints); testeq(subs(equation, x = solutions[1])); testeq(subs(equation, x = solutions[2]))

When you solve an equation, inequality or a system using the `IgnoreAnalyticConstraints`

option,
the solver uses an additional set of simplified mathematical rules.
These rules intentionally trade off mathematical strictness and correctness
for simplicity of the results. Although this option often leads to
the most practical and expected results, it also can lead to incorrect
results. For the set of rules `IgnoreAnalyticConstraints`

applies,
see the help page of the `solve`

command.

To verify such solutions, try using the same `IgnoreAnalyticConstraints`

option
for `testeq`

. When
you use this option, the `testeq`

command
does not guarantee that the solutions are correct everywhere on the
complex plane. The command checks that the solutions are correct for
the values of the parameters for which the rules applied by `IgnoreAnalyticConstraints`

are
valid:

testeq(subs(equation, x = solutions[1]), IgnoreAnalyticConstraints); testeq(subs(equation, x = solutions[2]), IgnoreAnalyticConstraints)

The `testeq`

command
did not verify both solutions. When trying to prove the equivalence
of two expressions, `testeq`

runs
random tests before applying `IgnoreAnalyticConstraints`

.
If tests for random values of identifiers show that expressions are
not equivalent, `testeq`

disregards
the `IgnoreAnalyticConstraints`

option and returns `FALSE`

.
To suppress running random tests, set the number of these tests to
zero:

testeq(subs(equation, x = solutions[2]), NumberOfRandomTests = 0, IgnoreAnalyticConstraints)

Verifying numeric results returned by the solver using `IgnoreAnalyticConstraints`

does
not require using the same option. Substitute numeric results into
the original equations and call `testeq`

to prove equivalence of the expressions
on both sides of the equations:

equation := x^(11/2) = 1: solution := solve(equation, IgnoreAnalyticConstraints); testeq(equation | solution[1])

Was this topic helpful?