Documentation

## If Results Differ from Expected

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.

### Verify Equivalence of Expected and Obtained Solutions

Symbolic solutions can be returned in different, but mathematically equivalent forms. MuPAD® continuously improves its functionality, including solvers and simplifiers. These improvements can cause different releases of MuPAD to return different forms of the same symbolic expressions. For example, when you solve the equation

`eq := ode({y''(t)=-a^2*y(t), y(0)=1, y'(PI/a)=0}, y(t)):`

```solution := solve(eq): eval(solution) assuming a <> 0```
` `

For the same equation, MuPAD 5.2 (R2009a) returns:

```solution := solve(eq): eval(solution) assuming a <> 0```
` `

### Note

`testeq` cannot compare sets. To test mathematical equality of the solutions returned as sets, compare each pair of the solutions individually.

If a returned solution differs from what you expect, test mathematical equality of the solutions:

`testeq(cos(a*t), (1/exp(a*t*I))/2 + exp(a*t*I)/2)`
` `

### Verify Equivalence of Solutions Containing Arbitrary Constants

#### Equal Arbitrary Constants

Verifying solutions with arbitrary constants can be a lot more complicated than verifying simple solutions without constants. In such solutions, consider arbitrary constants as symbolic parameters. In simple cases, you can assume that the parameters are equal. For example, solve the following ordinary differential equation. The form of the returned solution depends on the type of an equation. The solver can identify an equation with different equation types:

`reset()`
```o:= ode(y'(x) = (- 1/x + 2*I)*y(x) + 1/x*y(x)^2, y(x)): o1 := solve(o)```
` `

If you explicitly specify the type as Bernoulli, the solver returns another form of the result:

`o2 := solve(o, Type = Bernoulli)`
` `

Check the equality of these two solutions by calling the `testeq` command for each pair of the solutions. Remember that `testeq` cannot compare sets.

`testeq(o1, o2), testeq(o1, o2)`
` `

The second solution returns `FALSE` because `testeq` does not know that `C2` and `C3` are arbitrary constants. When you explicitly assume the equality of the constants, `testeq` confirms that the solutions are mathematically equal:

```testeq(o1, o2) assuming C1 = C2, testeq(o1, o2) assuming C1 = C2```
` `

#### Arbitrary Constants Representing Different Expressions

Verifying mathematical equality of the results by assuming that the arbitrary constants are equal does not always work. The solver can choose arbitrary constants to represent different expressions. For example, one form of a solution can include C1 and another form of the same solution can include . In this case, you need to assume that .

If the results include arbitrary constants, the number of elements in a solution set can depend on the form in which MuPAD returns the results. For example, if you specify the type of the following ordinary differential equation as Chini, the solver returns three separate solutions:

```o:= ode(y'(x) = x*y(x)^2 + x*y(x) + x, y(x)): L:= solve(o, Type = Chini)```
` `

Specifying the type of the same ordinary differential equation as Riccati gives you two separate solutions:

`M := solve(o, Type = Riccati)`
` `

When you specify the equation type as Riccati, the solver returns a more general result. This result combines the second and third elements of the set returned for the Chini type. The additional solution for the Chini equation appears at a particular value of the integration constant for the Riccati equation. Find the value of the constant at which the more general solution for the Riccati equation turns to the second solution for the Chini equation:

`solve(L = M, C5)`
` `

Use `evalAt` to verify that if the integration constant is 0, the solution for Riccati equation gives the additional solution that you see for Chini type:

`evalAt(M, C5 = 0)`
` `

You can find the dependency between the constants in the solutions returned for Riccati and Chini types. As a first step, rewrite the results using similar terms. For example, rewrite the expression with exponents in terms of tangents:

`m2 := rewrite(M, tan)`
` `

Define the constant `C5` in terms of `C4`:

`C5 := simplify(solve(L = m2, C5, IgnoreSpecialCases))`
` `

Now if you want to verify that the two forms of the solution are equivalent, substitute the constant in Riccati solution with this expression.

For more information on testing mathematical equivalence of the solutions, see Testing Results.

### Completeness of Expected and Obtained Solutions

#### Special Cases

The returned results can differ from what you expected due to incompleteness of the expected or the returned solution set. Complete sets of solutions account for all the special cases for all symbolic parameters and variables included in an equation. Complete solutions can be very large and complicated. Often you need only one practical solution from a long or infinite solution set. Some solvers are designed to return incomplete, but practical solutions. For example, consider the equation ax + b = y. When solving this equation in the MATLAB® Command Window, the toolbox ignores special cases:

>> solve('a*x + b = y')

ans =

-(b - y)/a

MuPAD returns the complete set of solutions accounting for all possible values of the symbolic parameters `a`, `b`, and `y`:

`solve(a*x + b = y, x)`
` `

Solving the equation in MuPAD with the `IgnoreSpecialCases` option, you get the same short result as in the MATLAB Command Window:

`solve(a*x + b = y, x, IgnoreSpecialCases)`
` `

#### Infinite Solution Sets

Some equations have an infinite number of solutions. When solving the same equation in the MATLAB Command Window, you get only one solution from the infinite set:

>> syms x;

>> solve(sin(x))

ans =

0

By default, the MuPAD solver returns all the solutions:

`S := solve(sin(x), x)`
` `

To get one element of the solution set, use the `solvelib::getElement` command:

`solvelib::getElement(S)`
` `

If you want the solver to return just one solution, use the `PrincipalValue` option:

`S := solve(sin(x), x, PrincipalValue)`
` `

`PrincipalValue` can help you shorten the results omitting all solutions, except one. The option does not allow you to select a particular solution.

#### Mathematical Modeling with Symbolic Math Toolbox

Get examples and videos