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 armor 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. (a) Write a Matlab script file to estimate the probability that Sir James slays 5 or more dragons in one year. (b) 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 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

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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site