s2rout1.m

来自「Industrial Mathematics」· M 代码 · 共 15 行

M
15
字号
% Routine 2.1A = 1;           % area of enclosing rectangle N = 10000;       % set the number of trialss = 0;           % initialize the success counterfor  i = 1:N     % begin trials x = rand;       % choose a random  x-coordinate y = rand;       %  choose a random y-coordinate if y  <=  exp(-x^3)  % if below the curve, then    s = s + 1;   % increment successes    end;         % end if end;             % end of each trialI = A*s/N        % integral= area*success/trials 

⌨️ 快捷键说明

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