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

📄 ballvol.m

📁 最近一段数学建模源程序汇编,适用于建模初学者练习
💻 M
字号:
function val = ballvol(n, m)
% BALLVOL Compute volume of unit ball in R^n
%
% Computes the volume of the n-dimensional unit ball 
% using monte-carlo method.
% usage: val = BallVol(n, m)
% where: n = dimension 
% m = number of realisations
% If the second argument is omitted, 1e4 is taken as default for m.

% (c) 1998, Rolf Krause, krause@math.fu-berlin.de

M = 1e4;
error = 0;
if(nargin <1|nargin > 2), error('wrong number of arguments'); end
if nargin == 2, M = m; end 

R = rand(n, M);
in = 0;
for i=1:M
if(norm(R(:,i),2) <= 1.0), in = in+1; end
end

val = 2^n*in/M;


⌨️ 快捷键说明

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