Sir James the Wise is a brave and noble knight Each day he r

Sir James the Wise is a brave and noble knight. Each day he rides out with his sword, lance, and shining armour to seek adventure in the halls of the Mathematics Department. On each day there is a 5% probability that Sir James will rescue a princess, there is a 2% probability that Sir James will slay a dragon, and a 93% probability that he simply has a cup of tea and goes home again without rescuing a princess or slaying a dragon. Write a Matlab script file to estimate the probability that Sir James slays 5 or more dragons in one year. In any given week, what is the probability that Sir James has a cup of tea more often than he rescues a princess? (Write a Matlab script file to compute this.)

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

 Sir James the Wise is a brave and noble knight. Each day he rides out with his sword, lance, and shining armour to seek adventure in the halls of the Mathemati

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site