symbolic trigonometrical function tan instead of log and imaginary equation

6 visualizzazioni (ultimi 30 giorni)
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 Commenti
Dyuman Joshi
Dyuman Joshi il 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 = 

Accedi per commentare.

Risposte (1)

Dyuman Joshi
Dyuman Joshi il 17 Mar 2023
Modificato: Dyuman Joshi il 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 = 

Categorie

Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by