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.

8 views (last 30 days)
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?

Accepted Answer

Rik
Rik on 23 Sep 2018
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
  1 Comment
Rik
Rik on 27 Sep 2018
Did this suggestion solve your problem? If so, please consider marking it as accepted answer. It will make it easier for other people with the same question to find an answer. If this didn't solve your question, please comment with what problems you are still having.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!