필터 지우기
필터 지우기

why sin(x) is different to sqrt(1-cos(x).^2)

조회 수: 3 (최근 30일)
Luis Isaac
Luis Isaac 2015년 12월 30일
답변: Walter Roberson 2015년 12월 30일
Dear, I'm new at matlab programming
I do not undestand why the following results s and s2 are different:
teta=0:pi/10:2*pi;
s=sin(teta);
s2=sqrt(1-cos(teta).^2);
sum(abs(s-s2))
The answer is
ans =
12.6275
But I think that the result should be 0 because sin(x)=sqrt(1-cos(x)^2) Why am I wrong?, where is my mistake?
Sorry for this question and thanks in advance
  댓글 수: 1
Luis Isaac
Luis Isaac 2015년 12월 30일
Sorry for the question: The answer is the absolute value: sqrt(x^2)~=x and sqrt(x^2)==abs(x)!!!

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

채택된 답변

Walter Roberson
Walter Roberson 2015년 12월 30일
sum(sin(teta).^2 + cos(teta).^2 -1) is 0 to within roundoff error.
What you are missing is the adjustment for sign, because sqrt() returns the positive square root only

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by