Why is sec(theta) different than sqrt(1+tan(theta).^2) in MATLAB?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
KostasK
el 16 de Dic. de 2021
Respondida: Voss
el 16 de Dic. de 2021
Hi all,
I just run into an odd problem; we all know the trigonometric identity . I use this identity in my code where I have a vector of angles of which I would like to calculate the secant of:
Psi = [0 320 40 280 80 240 120 200 160]*pi/180 ; % [rad]
x = [sec(Psi) ; sqrt(1 + tan(Psi).^2)] ;
>> x =
1.0000 1.3054 1.3054 5.7588 5.7588 -2.0000 -2.0000 -1.0642 -1.0642
1.0000 1.3054 1.3054 5.7588 5.7588 2.0000 2.0000 1.0642 1.0642
Above, I would expect both row vectors to be identical however it is visible that some numbers are returned as negative by the sec and postitive by the equivalent identity.
As a result I would like to ask: 1. why does this discrepancy exist to begin with 2. which one is correct?
0 comentarios
Respuesta aceptada
Walter Roberson
el 16 de Dic. de 2021
That is not a correct statement of the trig identity. The trig identity states that but that does not mean that -- it means that
1 comentario
Steven Lord
el 16 de Dic. de 2021
Más respuestas (2)
John D'Errico
el 16 de Dic. de 2021
Editada: John D'Errico
el 16 de Dic. de 2021
First, what you have written is NOT an identity. The identity is
sec(theta)^2 = 1 + tan(theta)^2
There IS a difference! You should remember that taking the square root is not valid there, because there can be a problem with the sign.
So this is not a problem in MATLAB, but a problem in your mathematics. Which one is correct? What is correct is to use the correct identity.
0 comentarios
Voss
el 16 de Dic. de 2021
sqrt(x) returns the positive square root of a real number x. For example, sqrt(4) returns 2, but -2 is also a square root of 4.
sec(x) returns the secant of the angle x, which will be positive or negative depending on which quadrant x is in.
So to answer your questions: 1. the discrepancy is due to the sqrt function picking the positive square root. 2. they are both correct.
The identity in question is more correctly written as sec(x)^2 == 1 + tan(x)^2 (the square of both sides of the one you stated), which does not have the ambiguity due to the sqrt.
0 comentarios
Ver también
Categorías
Más información sobre Biological and Health Sciences en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!