I'm having trouble (in Matlab) with the following problem:
there are 6 racers in a race. In vectors t1-t6 are previous times for each of the 6 racers (in this case, there are only 3 previous times for each of the racers).
t1=[30.01; 30.42; 30.68], t2=[30.00; 30.31; 30.55], t3=[29.98; 30.54; 30.32], t4=[28.89; 31.15; 30.44], t5=[29.66; 30.08; 31.25], t6=[28.72; 29.96; 31.18]
I want to calculate the probability of each racer to win the race. For example, if first racer wins, he has to do it with either his first time (probability 1/3), second or third with the condition that all other racers have bigger times than him. This group of commands should do that.
p=[0 0 0 0 0 0];
for i=min(t1):0.01:max(t1)
p(1)=p(1)+ sum((t1==i))/numel(t1) * sum((t2>i))/numel(t2)* sum((t3>i))/numel(t3)* sum((t4>i))/numel(t4)* sum((t5>i))/numel(t5)* sum((t6>i))/numel(t6);
end
for i=min(t2):0.01:max(t2)
p(2)=p(2)+ sum((t2==i))/numel(t2) * sum((t1>i))/numel(t1)* sum((t3>i))/numel(t3)* sum((t4>i))/numel(t4)* sum((t5>i))/numel(t5)* sum((t6>i))/numel(t6);
end
for i=min(t3):0.01:max(t3)
p(3)=p(3)+ sum((t3==i))/numel(t3) * sum((t2>i))/numel(t2)* sum((t1>i))/numel(t1)* sum((t4>i))/numel(t4)* sum((t5>i))/numel(t5)* sum((t6>i))/numel(t6);
end
for i=min(t4):0.01:max(t4)
p(4)=p(4)+ sum((t4==i))/numel(t4) * sum((t2>i))/numel(t2)* sum((t3>i))/numel(t3)* sum((t1>i))/numel(t1)* sum((t5>i))/numel(t5)* sum((t6>i))/numel(t6);
end
for i=min(t5):0.01:max(t5)
p(5)=p(5)+ sum((t5==i))/numel(t5) * sum((t2>i))/numel(t2)* sum((t3>i))/numel(t3)* sum((t4>i))/numel(t4)* sum((t1>i))/numel(t1)* sum((t6>i))/numel(t6);
end
for i=min(t6):0.01:max(t6)
p(6)=p(6)+ sum((t6==i))/numel(t6) * sum((t2>i))/numel(t2)* sum((t3>i))/numel(t3)* sum((t4>i))/numel(t4)* sum((t5>i))/numel(t5)* sum((t1>i))/numel(t1);
end
what i get is
p =
0.0247 0.0439 0.0562 0.2236 0.1481 0.3333
i've done the calculation manually and probability for fifth racer to win should be 0.1701 and sixth 0.4815. what i don't get is why the probabilities for the first four racers are correct, but the probability for 5th and 6th aren't? The logic is the same for all the racers. Can someone please explain what's wrong?

추가 답변 (1개)

Doctor Evil
Doctor Evil 2015년 12월 27일

0 개 추천

Thanks! So, to compare equality between a and b I just have to do something like this:
if abs(a-b)<=0.00001 % or something really small, then they're equal
And if I want to see if a is greater than b:
if abs(a-b)>=0.00001 % meaning they're not equal
if a>b % then a really is bigger
else % it's not bigger
else % they're equal
Would this work?

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2015년 12월 27일

댓글:

2015년 12월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by