why is not equal

2 Ansichten (letzte 30 Tage)
ueqweoıqwueoq
ueqweoıqwueoq am 26 Mär. 2024
Kommentiert: Rena Berman am 3 Apr. 2024
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 Kommentar
Rena Berman
Rena Berman am 3 Apr. 2024

(Answers Dev) Restored edit

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Steven Lord
Steven Lord am 26 Mär. 2024
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.

Kategorien

Mehr zu Function Creation finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by