Method on @sym: sol = solve (eqn)
Method on @sym: sol = solve (eqn, var)
Method on @sym: sol = solve (eqn1, …, eqnN)
Method on @sym: sol = solve (eqn1, …, eqnN, var1, …, varM)
Method on @sym: sol = solve (eqns, vars)
Method on @sym: [s1, …, sn] = solve (eqns, vars)

Symbolic solutions of equations, inequalities and systems.

Examples

syms x
solve(x == 2*x + 6, x)
  ⇒ ans = (sym) -6
solve(x^2 + 6 == 5*x, x);
sort(ans)
  ⇒ ans = (sym 2×1 matrix)
      ⎡2⎤
      ⎢ ⎥
      ⎣3⎦

Sometimes its helpful to assume an unknown is real:

syms x real
solve(abs(x) == 1, x);
sort(ans)
  ⇒ ans = (sym 2×1 matrix)
      ⎡-1⎤
      ⎢  ⎥
      ⎣1 ⎦

In general, the output will be a list of dictionaries. Each entry of the list is one a solution, and the variables that make up that solutions are keys of the dictionary (fieldnames of the struct).

syms x y
d = solve(x^2 == 4, x + y == 1);

% the first solution
d{1}.x
  ⇒ (sym) -2
d{1}.y
  ⇒ (sym) 3

% the second solution
d{2}.x
  ⇒ (sym) 2
d{2}.y
  ⇒ (sym) -1

But there are various special cases for the output (single versus multiple variables, single versus multiple solutions, etc). FIXME: provide a ’raw_output’ argument or something to always give the general output.

Alternatively:

[X, Y] = solve(x^2 == 4, x + y == 1, x, y)
  ⇒ X = (sym 2×1 matrix)
      ⎡-2⎤
      ⎢  ⎥
      ⎣2 ⎦
  ⇒ Y = (sym 2×1 matrix)
      ⎡3 ⎤
      ⎢  ⎥
      ⎣-1⎦

You can solve inequalities and systems involving mixed inequalities and equations. For example:

solve(x^2 == 4, x > 0)
  ⇒ ans = (sym) x = 2

syms x
solve(x^2 - 1 > 0, x < 10)
  ⇒ ans = (sym) (-∞ < x ∧ x < -1) ∨ (1 < x ∧ x < 10)

See also: @sym/eq, @sym/dsolve.

Package: symbolic