why is not equal

조회 수: 2 (최근 30일)
ueqweoıqwueoq
ueqweoıqwueoq 2024년 3월 26일
댓글: Rena Berman 2024년 4월 3일
sigma_0 = 2;
theta_deg = [0, 90, 180, 270];
theta_rad = deg2rad(theta_deg);
r = 1:0.1:2;
shear_Q = zeros(length(r), length(theta_rad));
for i = 1:length(theta_rad)
theta = theta_rad(i);
ksi = 1./r;
shear_Q(:, i) = (-1/2.*sigma_0.*(1-(3.*(ksi.^4))+(2.*(ksi.^2))).*sin(2.*theta));
end
Why doesn't it give the same result for 0 and 180 degrees? or 90 and 270 . The result must be 0 for 0 and 180 degrees
  댓글 수: 1
Rena Berman
Rena Berman 2024년 4월 3일

(Answers Dev) Restored edit

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

답변 (1개)

Steven Lord
Steven Lord 2024년 3월 26일
Rather than converting from degrees to radians and then computing the sine of the angle in radians, why not just use the sind function?
sigma_0 = 2;
theta_deg = [0, 90, 180, 270];
r = 1:0.1:2;
shear_Q = zeros(length(r), length(theta_deg));
shear_Q_rad = shear_Q;
for i = 1:length(theta_deg)
theta = theta_deg(i);
thetaR = deg2rad(theta);
ksi = 1./r;
shear_Q(:, i) = (-1/2.*sigma_0.*(1-(3.*(ksi.^4))+(2.*(ksi.^2))).*sind(2.*theta));
shear_Q_rad(:, i) = (-1/2.*sigma_0.*(1-(3.*(ksi.^4))+(2.*(ksi.^2))).*sin(2.*thetaR));
end
shear_Q
shear_Q = 11x4
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Of course, 2 times each of the angles in theta_deg makes the angle a multiple of 180 degrees, and the sine of an integer multiple of 180 degrees gives us 0.
shear_Q_rad
shear_Q_rad = 11x4
1.0e-15 * 0 0 0 0 0 -0.0740 0.1479 -0.2219 0 -0.1154 0.2308 -0.3461 0 -0.1388 0.2775 -0.4163 0 -0.1518 0.3036 -0.4554 0 -0.1588 0.3175 -0.4763 0 -0.1621 0.3242 -0.4862 0 -0.1632 0.3265 -0.4897 0 -0.1631 0.3261 -0.4892 0 -0.1621 0.3242 -0.4864
Now why are the elements of shear_Q_rad not all zero? Go ahead and type out the exact transcendental value of the constant π. Go ahead, I'll wait for you to get to the last digit. Roundoff error creeps in when you convert the angle in degrees into the angle in radians.
Alternately, you may find the sinpi function useful.

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by