- 8
- 0
- 约2.4千字
- 约 3页
- 2020-08-06 发布于云南
- 举报
蒙特卡洛方法求任意函数的积分
%Monte Carlo method
clear
clc
disp( Please enter the function f=@(x) );
keyboard
disp( Please enter the range of integration,a and b (ab) );
keyboard
disp( Please enter the number n of repeat );
keyboard
sum=0;
for i=1:n
k=rand(1);
x=(b-a)*k+a;
sum=sum+f(x);
end
fmean=sum/n;
intf=(b-a)*fmean;
disp( The value of this integral is );
disp(intf);
syms y
intr=int(f(y),y,a,b);
intr=double(intr);
disp( The real value of this integral is );
disp(intr);
dis=abs(intf-intr);
disp( The distance of two values is );
disp(dis);
蒙特卡洛方法仿真模拟三维随机游走
%The drunk walk
clear
clc
disp( Please enter the number n of steps );
keyboard;
x=0;
y=0;
z=0;
for i=1:n
x0=x;
y0=y;
z0=z;
direction=rand(1);
if (direction1/6)
x=x+1; %move right
elseif (direction2/6)
x=x-1; %move left
elseif (direction3/6)
y=y+1; %move forward
elseif (direction4/6)
y=y-1; %move backward
elseif (direction5/6)
z=z+1; %move upward
elseif (direction6/6)
z=z-1; %move downward
end
distance=sqrt(x^2+y^2+z^2);
if (distance5);
col= g ;
elseif (distance10);
col= b ;
elseif (distance15)
col= y ;
else
col=
您可能关注的文档
- 六年级作文续写题目.pdf
- 六校联考高二英语试卷.pdf
- 漏加工,错混料的8D.pdf
- 庐阳区八年级数学下学期阶段检测试题.pdf
- 潞王坟乡四年级数学第五单元导学案.pdf
- 论科学技术是第一生产力.pdf
- 氯气的化学方程式给高二学生.pdf
- 毛概试题C及答案.pdf
- 美国FAROFocus3D三维激光扫描仪矿山软件建模应用.pdf
- 美术试题高一美术试题.pdf
- 安徽省华师联盟2025-2026学年高三上学期1月质量检测生物试卷+答案.doc
- 安徽省华师联盟2025-2026学年高三上学期1月质量检测语文试卷+答案.doc
- 四川省绵阳南山中学实验学校2025-2026学年高三上学期1月月考数学含答案.doc
- 2026届辽宁省大连市高三上学期双基考试物理试卷+答案.doc
- 辽宁名校联盟2026年1月高三上期末联考质量检测化学含答案.doc
- 辽宁名校联盟2026年1月高三上期末联考质量检测生物含答案.doc
- 辽宁名校联盟2026年1月高三上期末联考质量检测英语含答案.doc
- 辽宁名校联盟2026年1月高三上期末联考质量检测政治含答案.doc
- 黑龙江省龙江教育联盟2026年1月高三上学期期末考试化学含答案.doc
- 黑龙江省龙江教育联盟2026年1月高三上学期期末考试生物含答案.doc
原创力文档

文档评论(0)