RobPazzuzu7
RobPazzuzu7

Reputation: 69

solving trigonometric equations taking all solutions

How can I solve trigonometric equations without loosing all the solutions in matlab ? For example :

solve(sin(theta) == 0, theta)

will return 0 but I want to know all the solutions, not only the first one.

Upvotes: 1

Views: 236

Answers (1)

obchardon
obchardon

Reputation: 10792

You can add some conditions to your equation.

For example start by declaring a symbolic variable theta:

syms theta

And now add as many conditions as you need:

solve(sin(theta) == 0,theta>=-2*pi,theta<=2*pi, theta)

You can also set assumption on symbolic variable, it is more clear in my opinion.

assume(-2*pi <= theta <= 2*pi)
out = solve(sin(theta) == 0, theta)

In both case the output will be:

out =

     0
    pi
   -pi
 -2*pi
  2*pi

If needed, you can order the result with:

sym(sort(double(out)))

Upvotes: 3

Related Questions