Why is tan(a) not equal to sin(a)/cos(a)

6 visualizzazioni (ultimi 30 giorni)
cpistor
cpistor il 24 Apr 2022
Risposto: Paul il 25 Apr 2022
trying to simplify sin(alpha)/cos(alpha) Matlab does not give tan(alpha), why?
also isolating alpha from b == sin(alpha)/cos(alpha) does not give alpha = atan(b), why?
>> syms alpha b
equ1=b==sin(alpha)/cos(alpha)
simplify(equ1)
equ1=isolate(equ1,alpha)
equ1 =
b == sin(alpha)/cos(alpha)
ans =
b == sin(alpha)/cos(alpha)
equ1 =
alpha == -log((- b^2 - 1)^(1/2)/(b + 1i))*1i
  1 Commento
David Goodmanson
David Goodmanson il 24 Apr 2022
Modificato: David Goodmanson il 24 Apr 2022
Hi cpistor,
to be honest, there are certain situations where Matlab symbolics is not all that bright. But the expression for alpha on your last line is a good expression for atan(b).
( For complex input, the expression does not always exactly agree with atan. Somtimes there is disagreement by pi, reflecting the pi ambiguity in the tan function, i.e. tan(theta) = tan(theta +-pi) )

Accedi per commentare.

Risposte (1)

Paul
Paul il 25 Apr 2022
It's kind of a pain, but ....
syms b alpha
eq1 = b == sin(alpha)/cos(alpha);
eq1 = rewrite(eq1,'tan')
eq1 = 
eq1 = lhs(eq1) == simplify(rhs(eq1))
eq1 = 
alpha_sol = solve(eq1,alpha)
alpha_sol = 
Actually, I'm kind of surprised the SMT yileds this result w/o some further assumptions on the range of alpha. Suppose alpha = 3*pi/4.
syms b alpha
alpha = 3*sym(pi)/4;
b = sin(alpha)/cos(alpha);
atan(b)
ans = 
OTOH, if we solve() eq1 w/o the simplifications, we get
syms b alpha
eq1 = b == sin(alpha)/cos(alpha);
alpha_sol = solve(eq1,alpha,'Real',true,'ReturnConditions',true);
alpha_sol.alpha
ans = 
alpha_sol.conditions
ans = 
I think those solutions are basically atan(b) and atan(b) +- pi.

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by