⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idiots2.m

📁 一些常被用于教学或者参考的概率论的实例的源代码
💻 M
字号:
%idiots2.m/created by PJNahin for "Duelling Idiots"(7/6/98)
%This m-file evaluates the theoretical probability that idiot A
%wins the duel with idiot B, using the revised duelling rules
%described in the problem assignment. The calculations are done
%in symbolic form to avoid round-off errors (see the definition
%of the variable r below). The final result is printed to 26 digits
%and is printed on the screen after each additional term is added
%to allow watching the answer converge.
%
%
S=0;                   %initialize finite geometric series sum that
                       %appears in each term;
T=1;                   %the first term in the brackets for P(A);
r=sym('5/6');
e=3;                   %starting value of exponent in the factor that
                       %multiplies the finite geometric series;
incr=7;                %initial amount to be added to exponent to get
                       %the next exponent;                       
startp=0;              %initial value of power in the first term of
                       %the present finite geometric series;
stopp=2;               %initial value of power in the last term of
                       %the present finite geometric series;
for k=1:30             %the '30' is somewhat arbitrarily picked to
                       %be sufficiently large to see convergence;
   for i=startp:stopp  %form finite geometric sum from old sum by
                       %adding-on two new terms (the FIRST sum has
                       %THREE terms);
      S=S+r^i;
   end
M=r^e;                 %factor to multiply geometric series;
T=T+M*S;               %multiply, and add to old total;
startp=stopp+1;        %up-date starting power for new terms to add
                       %to old sum;
stopp=startp+1;        %up-date final power for new terms to add
                       %to old sum;
e=e+incr;              %up-date exponent of factor to multiply
                       %with new geometric series;
incr=incr+4;           %up-date exponent increment;
vpa(T/6,26)            %print variable precision arithmetic value (26
                       %digits) of present value for P(A);
end                    %terminate the program via the keyboard when
                       %convergence is observed;

                    
                       

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -