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

33 次查看(过去 30 天)
cpistor
cpistor 2022-4-24
回答: Paul 2022-4-25
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 个评论
David Goodmanson
David Goodmanson 2022-4-24
编辑:David Goodmanson 2022-4-24
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) )

请先登录,再进行评论。

回答(1 个)

Paul
Paul 2022-4-25
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.

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by