Sir James the Wise is a brave and noble knight Each day he r
Solution
a) MATLAB code for estimatation of the probablity that Sir James slays 5 or more dragrons in one year is as follows:
clear all;
ps = 0.02; %slay down a dragon probability
pn = 0.05 + 0.93; %not slay down a dragon probability
t = 365; %Days in a year
n = 5; % 5 days
% Probablity of slaying down 0 to 4 dragons in an year
p1 = 0;
for i = 1:n
p1 = p1 + nchoosek(t,i-1)*ps^(i-1)*pn^(t-(i-1));
end
%probablity is negated to get 5 or more slaying down dragon probablity
p1 = 1 - p1;
disp(p1)
Output:
0.8533
b) clear all;
a1 = 0.05;
a2 = 0.02;
a3 = 0.93;
n = 7; %week
p1 = 0;
for i =1:7
c3 = i; %days for which Sir James has a cup of tea
for j = 1:c3
c1=j-1; %days for which Sir James rescues a princess, which should be less than total no. of days of cup of tea
c2 = n - c1- c3; %Remaining days that are equal to slaying dragon
p1 = p1 + ((a1^c1)*(a2^c2)*(a3^c3));
if c2==0
break;
end
end
end
disp(p1)
Output :
0.6499
