5 计算机模拟实验Word格式文档下载.docx
《5 计算机模拟实验Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《5 计算机模拟实验Word格式文档下载.docx(9页珍藏版)》请在冰豆网上搜索。
2、数学模拟
在一定的假设条件下,运用数学运算模拟系统的运行,称为数学模拟。
现代的数学模拟都是在计算机上进行的,称为计算机模拟。
计算机模拟可以反复进行,改变系统的结构和系数都比较容易。
在实际问题中,面对一些带随机因素的复杂系统,用分析方法建模常常需要作许多简化假设,与面临的实际问题可能相差甚远,以致解答根本无法应用。
这时,计算机模拟几乎成为唯一的选择。
time=0;
tt=0;
valume=2000;
total=2;
rate=N[total/valume,7];
Print["
time"
"
"
valume"
total"
rate"
];
While[rate<
0.2,
time=time+1;
valume=valume+2;
total=total+3-4rate;
rate=total/valume;
If[time>
=10,
Print[tt+time,"
valume,"
N[total,3],"
N[rate,3]];
tt=tt+time;
time=0]
note:
设t时刻的盐水浓度为r(t),水池中的含盐量为y(t),则
t时刻的盐水量是2000+(6-4)t=2000+2t,故
y(t)=(2000+2t)r(t),
在[t,t+△t]时间内,容器内盐量的改变量是:
y(t+△t)-y(t)=(2000+2t+2△t)r(t+△t)-(2000+2t)r(t)
=(6*0.5-4r(t))△t
(2000+2t)r'
(t)+6r(t)=3
DSolve[{r'
[t]==(3-6r[t])/(2000+2t),r[0]==0.001},r[t],t]
r=r[t]/.%[[1]]
Plot[r,{t,0,200}]
t=12.;
dt=0.02;
v=1;
n=t/dt;
robit={{{0,10}},{{10,10}},{{10,0}},{{0,0}}};
For[j=1,j<
=n,j++,
For[i=1,i<
=4,i++,
xx1=robit[[i,j,1]];
yy1=robit[[i,j,2]];
If[i!
=4,xx2=robit[[i+1,j,1]];
yy2=robit[[i+1,j,2]],
xx2=robit[[1,j,1]];
yy2=robit[[1,j,2]]];
dd=Sqrt[(xx2-xx1)^2+(yy2-yy1)^2]//N;
xx1=xx1+v*dt*(xx2-xx1)/dd;
yy1=yy1+v*dt*(yy2-yy1)/dd;
robit[[i]]=
Append[robit[[i]],{xx1,yy1}]
]
];
g=Graphics[
{Line[robit[[1]]],Line[robit[[2]]],
Line[robit[[3]]],Line[robit[[4]]],
Line[{{0,0},{0,10},{10,10},{10,0},{0,0}}]}];
Show[g,AspectRatio->
Automatic]
Animation
For[i=1,i<
=600,i=i+10,g=Graphics[
{Line[Take[robit[[1]],i]],Line[Take[robit[[2]],i]],
Line[Take[robit[[3]],i]],Line[Take[robit[[4]],i]],
Line[{{0,0},{0,10},{10,10},{10,0},{0,0}}]}];
Show[g,AspectRatio->
Automatic]]
gotonext[x_]:
=
x+{Random[Real,{-1,1}],Random[Real,{-1,1}]};
rdmmove[n_]:
=Module[{location},
location=NestList[gotonext,{0,0},n];
Show[Graphics[{Line[location]}],
AspectRatio->
Automatic,
PlotRange->
All]]
rdmmove[50]
rdmmove[1000]
Animation
location=NestList[gotonext,{0,0},100];
mm=Min[location];
nn=Max[location];
=100,i++,
Show[Graphics[{Line[Take[location,i]]}],
Automatic,AxesOrigin->
{0,0},
{{mm,nn},{mm,nn}}]]
pts[n_]:
=Table[{Random[],Random[]},{k,n}]
ListPlot[pts[1000],
PlotStyle->
PointSize[0.003],
AspectRatio->
rdmIntegrate[n_]:
=Module[{k,p=0.0},
Do[If[Random[]<
=Sqrt[1-Random[]^2],k=1,k=0];
p=p+k,{x,n}];
Return[p/n]]
4*rdmIntegrate[1000]
?
[a,b]