# symbolic trigonometrical function tan instead of log and imaginary equation

5 views (last 30 days)
Edited: Dyuman Joshi on 17 Mar 2023
I have this simple code
syms a b x real;
solve(a*sin(x) == b*cos(x),x)
%the answer should looks like x= -atan(b/a)
%I got
-log((a^2 + b^2)^(1/2)/(a - b*1i))*1i
-log(-(a^2 + b^2)^(1/2)/(a - b*1i))*1i
is there a way to avoid complex and log and just make it simple trigonometrical function?
##### 2 CommentsShow 1 older commentHide 1 older comment
Dyuman Joshi on 17 Mar 2023
Walter, rewrite() does convert the solution in terms of atan but it still contains complex values
syms a b x real
%assumptions
sol=solve(a*sin(x) == b*cos(x),x)
sol =
rewrite(sol,"atan")
ans =

Dyuman Joshi on 17 Mar 2023
Edited: Dyuman Joshi on 17 Mar 2023
syms a b x real
sol1=solve(a*sin(x) == b*cos(x),x,'Real',true)
sol1 =
The solution obtained above can be derived by changing sin and cos to half angle terms, dividing the equation by (cos (x/2))^2 thus converting the equation into a quadratic equation in tan(x/2) and solving it.
Though I do not know why this particular solution is obtained as the output instead of atan(b/a).
To obtain a general solution and conditions on the solution.
sol2=solve(a*sin(x) == b*cos(x),x,'Real',true, 'ReturnConditions', true)
sol2 = struct with fields:
x: [2×1 sym] parameters: k conditions: [2×1 sym]
sol2.x
ans =
sol2.conditions
ans =

### Categories

Find more on Assumptions in Help Center and File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!