Main Content

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 = 


params = k
conds = kZC0

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 = 


ans = logical

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 = 


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 = 


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 = 


params1 = k
conds1 = 0<C4C<π+4πkπ+4πk<14CC<0π+4πk<4C14C<π+4πk

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 = 


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

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


solve(conds3, params)
ans =