主题
: [MATLAB混合编程]
关于matlab运行中出现的错误,进行纠错!
查看单个帖子
2012-03-04, 11:50
#
2
peterjim
游客
帖子: n/a
回复: 关于matlab运行中出现的错误,进行纠错!
clear all
clc
counter=0;i=1;
x=rand(1,100000);n=length(x);
for i=1:n
if x(i)<=1/2&x(i)>=0
counter=counter+1;
else
counter=counter;
end
i=i+1;
end
p=counter/n
首先,所谓蒙特卡洛就是一个随机算法,随机肯定每一次结果不同,第二,你的代码中有个错误rand,
peterjim