Why do trigonometric functions in MATLAB require different computation times when provided the same-sized input?
Show older comments
I see that the third and fifth cases take significantly longer, approximately 6 times longer, than the other cases even though they have the same size input.
varA = rand(1,78);
c = -256:255;
w = -256:255;
x = -256:255;
y = -256:255;
z = -256:255;
z = z/(1000*rand(1));
for ii = 1:50
%Case 1
% Control case
twopicA = 2 * pi * c' * varA;
ccos = cos(twopicA); % Time 1
csin = sin(twopicA); % Time 2
%Case 2
% Incrementing + case
w = w + 1;
twopiwA = 2 * pi * w' * varA;
wcos = cos(twopiwA); % Time 1
wsin = sin(twopiwA); % Time 2
%Case 3
% Incrementing + (varying integer) case
x = x + 10000*ii;
twopixA = 2 * pi * x' * varA;
xcos = cos(twopixA); % Time 1
xsin = sin(twopixA); % Time 2
%Case 4
% Incrementing + (non-integer) case
y = y + rand(1);
twopiyA = 2 * pi * y' * varA;
ycos = cos(twopiyA); % Time 1
ysin = sin(twopiyA); % Time 2
%Case 5
% Incrementing + (varying-non-integer) case
z = z + 10000*ii*rand(1);
twopizA = 2 * pi * z' * varA;
zcos = cos(twopizA); % Time 1
zsin = sin(twopizA); % Time 2
end
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!