# How do I get all solutions of the equation cos(x)==cos(3x) using solve() from Symbolic Math Toolbox ?

6 views (last 30 days)
Angelo Cacini on 25 Mar 2018
Commented: Angelo Cacini on 26 Mar 2018
I’ve tried the following code:
syms x
h(x)=cos(x)==cos(3*x);
[sol,par,cond]=solve(h,x,'returnconditions',true)
sol =
pi*k
par =
k
cond =
in(k, 'integer')
But I expected to obtain: k*pi/2.
Where am I wrong ? Thanks in advance.
##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

### Answers (1)

David Goodmanson on 26 Mar 2018
Hi Angelo,
You didn't go wrong, it's missing half of the roots. But this works
h(x)=sin(x+pi/2)==sin(3*x+pi/2);
go figure.
##### 1 CommentShow -1 older commentsHide -1 older comments
Angelo Cacini on 26 Mar 2018
Hi David, many thanks for your reply. This is a good workaround. Regards

Sign in to comment.

### Categories

Find more on Calculus in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!