蒙特卡洛方法matlab程序

2023-02-20 16:21:22   文档大全网     [ 字体: ] [ 阅读: ]

#文档大全网# 导语】以下是®文档大全网的小编为您整理的《蒙特卡洛方法matlab程序》,欢迎阅读!
蒙特卡洛,程序,方法,matlab
-------------精选文档-----------------

蒙特卡洛方法matlab程序



% Example Monte Carlo Simulation in Matlab % Function: y = x2^2/x1 %

% Generate n samples from a normal distribution % r = ( randn(n,1) * sd ) + mu % mu : mean

% sd : standard deviation %

% Generate n samples from a uniform distribution % r = a + rand(n,1) * (b-a) % a : minimum % b : maximum

n = 100000; % The number of function evaluations % --- Generate vectors of random inputs % x1 ~ Normal distribution N(mean=100,sd=5) % x2 ~ Uniform distribution U(a=5,b=15) x1 = ( randn(n,1) * 5 ) + 100; x2 = 5 + rand(n,1) * ( 15 - 5 ); % --- Run the simulation

% Note the use of element-wise multiplication y = x2.^2 ./ x1;

% --- Create a histogram of the results (50 bins) hist(y,50);

% --- Calculate summary statistics y_mean = mean(y) y_std = std(y) y_median = median(y)

可编辑


本文来源:https://www.wddqxz.cn/a4bfba6cbd1e650e52ea551810a6f524ccbfcbbb.html

相关推荐