MATLAB: A car laps a racetrack in 90s. The speed of the car at each 6 second interval is determined using a radar gun and is given from the beginning of the lap, in m/s.

arrayhomeworkwhile loop

Length of track is estimated by ? = 2ℎ/45 ∑ n(i=0) 7*?(?4?−4) + 32*?(?4?−3) + 12*?(?4?−2) + 32*?(?4?−1) + 7*?(?4?) This is my code:
function [ ] = Q2( ~ )
k=[0,1,2,3,4,5,6,7,8,9,10,11,12];
t=[0,6,12,18,24,30,36,42,48,54,60,66,72];
s=[0,134,148,156,147,133,121,99,85,78,89,104,92];
L=0;
i=1;
n=(t(13)-t(1))./4*6;
while(i<=n)
L=L+(7*s(i)-4)+(32*s(4*i)-3)+(12*s(4*i)-2)+(32*s(4*i)-1)+(7*s(4*i));
i=i+1;
end
L=L*(2*6./45);
disp('L');
end
But i end up getting result as index exceeds number of array elements. Why?

Best Answer

Two changes (also, k is unused):
function Q2(~)
k=[0,1,2,3,4,5,6,7,8,9,10,11,12];
t=[0,6,12,18,24,30,36,42,48,54,60,66,72];
s=[0,134,148,156,147,133,121,99,85,78,89,104,92];
L=0;
i=1;
n=(t(13)-t(1))/(4*6);%changed from ./4*6
while(i<=n)
L=L+(7*s(i)-4)+(32*s(4*i)-3)+(12*s(4*i)-2)+(32*s(4*i)-1)+(7*s(4*i));
i=i+1;
end
L=L*(2*6./45);
disp(L);%changed from 'L'
end