- #1
- 310
- 0
Homework Statement
Calculate the time taken to compute sum of 1/k^3 from 1 -> 1000 using both loops and vectorised commands using tic toc.
Homework Equations
The Attempt at a Solution
tic
n = 1e3; % number of terms in the sum
s = 1; % accumulator variable (for the sum)
for k = 2:n
s = s + 1/k^3;
end
s; % print value of variable s
toc
k = 1:1000;
y = 1./k.^3;
sum(y);
toc
Am I using tic toc in the correct way? If not, how should they be used and if I run this code will the time be displayed in the command window?