# Solving equation(s): solve cSolve

### 5.55.6 Solving equation(s): solve cSolve

The solve command solves an equation or a system of polynomial equations. In real mode, solve returns only real solutions; to have solve return the complex solutions, switch to complex mode (e.g.by checking Complex in the cas configuration, see Section 2.5.5).

The cSolve command is identical to solve, except it returns the complex solutions whether in real mode or complex mode.

To solve an equation:

- solve takes one mandatory argument and one optional argument:
  - eqn, an equation or expression assumed to be zero.
  - Optionally, x, a variable (by default, x=x).
- solve(eqn,x) returns the solution to the equation.

For trigonometric equations, solve returns by default the principal solutions. To have all the solutions check All_trig_sol in the cas configuration (see Section 2.5.7, item 19).

Examples:

- Solve x4−1=3
  Input:
  solve(x^4-1=3)
  Output (in real mode):

  ⎡
  ⎢
  ⎣

  √

  2

  ,−

  √

  2

  ⎤
  ⎥
  ⎦

  Output (in complex mode):

  ⎡
  ⎢
  ⎣

  √

  2

  ,−

  √

  2

  ,i

  √

  2

  ,−i

  √

  2

  ⎤
  ⎥
  ⎦

  Also:
  Input:
  cSolve(x^4-1=3)
  Output (in any mode):

  ⎡
  ⎢
  ⎣

  −

  √

  2

  ,

  √

  2

  ,−

  √

  2

  i,

  √

  2

  i

  ⎤
  ⎥
  ⎦

- Solve exp(x)=2
  Input:
  solve(exp(x)=2)
  Output:

  ⎡ ⎣ | ln | ⎛ ⎝ | 2 | ⎞ ⎠ | ⎤ ⎦

- Solve cos(2*x)=1/2
  Input:
  solve(cos(2*x)=1/2)
  Output:

  ⎡
  ⎢
  ⎢
  ⎣

  −

  π
  6

  ,

  π
  6

  ⎤
  ⎥
  ⎥
  ⎦

  Output (with All_trig_sol checked):

  ⎡
  ⎢
  ⎢
  ⎣

  6π n0 + π
  6

  ,

  6π n0 − π
  6

  ⎤
  ⎥
  ⎥
  ⎦

To solve a system of polynomial equations:

- solve takes one mandatory argument and one optional argument:
  - eqns, a list of polynomial equations.
  - vars, a list of variables.
- solve(eqns,vars) returns the solutions to the system of equations.

#### Examples.

- Find x,y such that x+y=1,x−y=0
  Input:
  solve([x+y=1,x-y],[x,y])
  Output:

  ⎡
  ⎢
  ⎢
  ⎣

  ⎡
  ⎢
  ⎢
  ⎣

  1
  2

  ,

  1
  2

  ⎤
  ⎥
  ⎥
  ⎦

  ⎤
  ⎥
  ⎥
  ⎦

- Find x,y such that x2+y=2,x+y2=2
  Input:
  solve([x^2+y=2,x+y^2=2],[x,y])
  Output:

  ⎡
  ⎢
  ⎢
  ⎢
  ⎢
  ⎢
  ⎣

  ⎡
  ⎣

  1,1

  ⎤
  ⎦

  ,

  ⎡
  ⎣

  −2,−2

  ⎤
  ⎦

  ,

  ⎡
  ⎢
  ⎢
  ⎢
  ⎢
  ⎢
  ⎣

  √

  5

  +1

  2

  ,−

  ⎛
  ⎜
  ⎜
  ⎝

  √

  5

  +1

  2

  ⎞
  ⎟
  ⎟
  ⎠

  2

  +2

  ⎤
  ⎥
  ⎥
  ⎥
  ⎥
  ⎥
  ⎦

  ,

  ⎡
  ⎢
  ⎢
  ⎢
  ⎢
  ⎢
  ⎣

  −

  √

  5

  +1

  2

  ,−

  ⎛
  ⎜
  ⎜
  ⎝

  −

  √

  5

  +1

  2

  ⎞
  ⎟
  ⎟
  ⎠

  2

  +2

  ⎤
  ⎥
  ⎥
  ⎥
  ⎥
  ⎥
  ⎦

  ⎤
  ⎥
  ⎥
  ⎥
  ⎥
  ⎥
  ⎦

  [(sqrt(5)+1)/2,(1-sqrt(5))/2]]
- Find x,y,z such that x2−y2=0,x2−z2=0
  Input:
  solve([x^2-y^2=0,x^2-z^2=0],[x,y,z])
  Output:

  ⎡ ⎣ | ⎡ ⎣ | x,x,x | ⎤ ⎦ | , | ⎡ ⎣ | x,−x,−x | ⎤ ⎦ | , | ⎡ ⎣ | x,x,−x | ⎤ ⎦ | , | ⎡ ⎣ | x,−x,x | ⎤ ⎦ | ⎤ ⎦

- Find the intersection of a straight line (given by a list of equations) and a plane.
  For example, let D be the straight line with cartesian equations [y−z=0,z−x=0] and let P the plane with equation x−1+y+z=0. Find the intersection of D and P.
  Input:
  solve([[y-z=0,z-x=0],x-1+y+z=0],[x,y,z])
  Output:

  ⎡
  ⎢
  ⎢
  ⎣

  ⎡
  ⎢
  ⎢
  ⎣

  1
  3

  ,

  1
  3

  ,

  1
  3

  ⎤
  ⎥
  ⎥
  ⎦

  ⎤
  ⎥
  ⎥
  ⎦

- Input:
  cSolve([-x^2+y=2,x^2+y],[x,y])
  Output:

  ⎡ ⎣ | ⎡ ⎣ | −i,1 | ⎤ ⎦ | , | ⎡ ⎣ | i,1 | ⎤ ⎦ | ⎤ ⎦