Why is sec(theta) different than sqrt(1+tan(theta).^2) in MATLAB?

조회 수: 15 (최근 30일)
KostasK
KostasK 2021년 12월 16일
답변: Voss 2021년 12월 16일
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?

채택된 답변

Walter Roberson
Walter Roberson 2021년 12월 16일
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
Steven Lord
Steven Lord 2021년 12월 16일
Many of the entries in the the Pythagorean identities section on this Wikipedia page use ±.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

John D'Errico
John D'Errico 2021년 12월 16일
편집: John D'Errico 2021년 12월 16일
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.

Voss
Voss 2021년 12월 16일
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.

카테고리

Help CenterFile Exchange에서 Digital Filtering에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by