Sir James the Wise is a brave and noble knight Each day he r
Solution
a) MATLAB script for estimating the probablity that Sir James slays 5 or more dragrons in one year is given as below:
clear all;
p=0.02; %probablity of slaying dragon
q=0.05+0.93; %probablity of not slaying a dragon
td=365; %total 365 days considered in an year
n=5; %for 5 no. of days
%probablity calculated for 0 to 4 dragons in an year
prob=0;
for i = 1:n
prob=prob+nchoosek(td,i-1)*p^(i-1)*q^(td-(i-1));
end
%probablity is negated to get 5 or more dragon probablity
prob=1-prob;
disp(prob)
Output:
0.8533
b) MATLAB script for given problem is as below:
clear all;
p1=0.05;
p2=0.02;
p3=0.93;
n=7; %no. of days in a week
prob=0;
for i=1:7
cp3=i; %no. of days Sir James has a cup of tea
for j=1:cp3
cp1=j-1; %no. of days Sir James rescue a princess, which is less than no. of day of cup of tea
cp2=n-cp1-cp3; %remaining no. of days i.e. slaying dragon
prob=prob+((p1^cp1)*(p2^cp2)*(p3^cp3));
if cp2==0
break;
end
end
end
disp(prob)
Output :
0.6499
