symbolic trigonometrical function tan instead of log and imaginary equation

5 views (last 30 days)
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?
Dyuman Joshi
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
sol=solve(a*sin(x) == b*cos(x),x)
sol = 
ans = 

Sign in to comment.

Answers (1)

Dyuman Joshi
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]
ans = 
ans = 

Community Treasure Hunt

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

Start Hunting!