Documentation

Solve Parametric Equations in ReturnConditions Mode

This example shows you how to solve parameterized algebraic equations using the Symbolic Math Toolbox.

To solve algebraic equations symbolically, use the solve function. The solve function can provide complete information about all solutions of an equation, even if there are infinitely many, by introducing a parameterization. It can also provide information under which conditions these solutions are valid. To obtain this information, set the option ReturnConditions to true.

Solve the equation sin(C*x) = 1. Specify x as the variable to solve for. The solve function handles C as a constant. Provide three output variables for the solution, the newly generated parameters in the solution, and the conditions on the solution.

syms C x
eq = sin(C*x) == 1;
[solx, params, conds] = solve(eq, x, 'ReturnConditions', true)
solx =

$\frac{\frac{\pi }{2}+2 \pi k}{C}$

params = $k$
conds = $C\ne 0\wedge k\in \mathbb{Z}$

To verify the solution, substitute the solution into the equation using subs. To work on under the assumptions in conds for the rest of this example, use assume. Test the solution using isAlways. The isAlways function returns logical 1 (true) indicating that the solution always holds under the given assumptions.

SolutionCorrect = subs(eq, x, solx)
SolutionCorrect =

$\mathrm{sin}\left(\frac{\pi }{2}+2 \pi k\right)=1$

assume(conds)
isAlways(SolutionCorrect)
ans = logical
1

To obtain one solution out of the infinitely many solutions, find a value of the parameters params by solving the conditions conds for the parameters; do not specify the ReturnConditions option. Substitute this value of k into the solution using subs to obtain a solution out of the solution set.

k0 = solve(conds, params)
k0 = $0$
subs(solx, params, k0)
ans =

$\frac{\pi }{2 C}$

To obtain a parameter value that satisfies a certain condition, add the condition to the input to solve. Find a value of the parameter greater than 99/4 and substitute in to find the solution.

k1 = solve([conds, params > 99/4], params)
k1 = $26$
subs(solx, params, k1)
ans =

$\frac{105 \pi }{2 C}$

To find a solution in a specified interval, you can solve the original equation with the inequalities that specify the interval.

[solx1, params1, conds1] = solve([eq, x > 2, x < 7], x, 'ReturnConditions', true)
solx1 =

$\frac{\pi +4 \pi k}{2 C}$

params1 = $k$
conds1 = $\left(0

Alternatively, you can also use the existing solution, and restrict it with additional conditions. Note that while the condition changes, the solution remains the same. The solve function expresses solx and solx1 with different parameterizations, although they are equivalent.

[~, ~, conds2] = solve(x == solx, x < 7, x > 2, x, 'ReturnConditions', true)
conds2 =

$\frac{4}{\pi }<\frac{4 k+1}{C}\wedge \frac{4 k+1}{C}<\frac{14}{\pi }$

Obtain those parameter values that satisfy the new condition, for a particular value of the constant C:

conds3 = subs(conds2, C, 5)
conds3 =

$\frac{4}{\pi }<\frac{4 k}{5}+\frac{1}{5}\wedge \frac{4 k}{5}+\frac{1}{5}<\frac{14}{\pi }$

solve(conds3, params)
ans =

$\left(\begin{array}{c}2\\ 3\\ 4\\ 5\end{array}\right)$

Mathematical Modeling with Symbolic Math Toolbox

Get examples and videos