解:设甲达时间x乙达时间y求等15分钟(025时)满足式xy≤025编写matlab程序:
clear
N100000
n0
for i1N
xunifrnd(03)
ynormrnd(21)
if abs(xy)<025
nn+1
end
end
pronN
:
pro
01373
求两见面概率pro01373
解毕
2 编程模拟顾客达服负指数分布(λ10)服务时间分服正态分布(均值9方差4)定长时间(T9)排队程求顾客均等时间逗留时间
解:服务时间服正态分布(均值9方差4)时编写matlab程序:
clc
singlesurcetime0 service time of any customer
wholetime0 whole time
survicertime0 whole survice time of waiters
customerwaittime0 time of customer waitting
lamda10 average interval time of two coming customers
queneexprnd(lamda)
n1
while n<100000
while singlesurcetime>quene(end)
quene(end+1)quene(end)+exprnd(lamda)
nn+1
end
if length(quene)<2
quene(end+1)quene(end)+exprnd(lamda)
nn+1
end
quenequenesinglesurcetime
wholetimewholetime+singlesurcetime
survicertimesurvicertime+singlesurcetime
if quene(1)>0 the desk is empty
wholetimewholetime+quene(1)
quenequenequene(1)
end
for k1length(quene)
if quene(k)<0
customerwaittimecustomerwaittimequene(k) add all waiting time
quene(k)0 as the time has been added
end
end
quene(1)[] the first customer start to accept survice
singlesurcetimenormrnd(94) generate the customer's survice time
end
customerwaittimecustomerwaittimen
averagetimesurvicertimen+customerwaittime
:
customerwaittime 502186
averagetime 592203
服务时间服定长时间(T9)时编写matlab程序:
clc
singlesurcetime9 service time of any customer
wholetime0 whole time
survicertime0 whole survice time of waiters
customerwaittime0 time of customer waitting
lamda10 average interval time of two coming customers
queneexprnd(lamda)
n1
while n<100000
while singlesurcetime>quene(end)
quene(end+1)quene(end)+exprnd(lamda)
nn+1
end
if length(quene)<2
quene(end+1)quene(end)+exprnd(lamda)
nn+1
end
quenequenesinglesurcetime
wholetimewholetime+singlesurcetime
survicertimesurvicertime+singlesurcetime
if quene(1)>0 the desk is empty
wholetimewholetime+quene(1)
quenequenequene(1)
end
for k1length(quene)
if quene(k)<0
customerwaittimecustomerwaittimequene(k) add all waiting time
quene(k)0 as the time has been added
end
end
quene(1)[] the first customer start to accept survice
end
customerwaittimecustomerwaittimen
averagetimesurvicertimen+customerwaittime
:
customerwaittime 391112
averagetime 481107
解毕
3(选做)列火车约午1点离开A站规律:
离站时间 13:00 13:05 13:10
概率 07 02 01
火车AB途中需均时间30分2分钟标准差果赶趟火车站B达时间分布
时间 13:28 13:30 13:32 13:34
概率 03 04 02 01
问赶列火车概率少?
解:题中概率分布满足matlab中已分布通产生机数判断机数区间方法题中概率分布matlab程序:
clc
clear
N10000
n0
for i1N
xrand
traintimenormrnd(304)
if x<03
setouttime0
youarrive28
elseif x<07
setouttime0
youarrive30
elseif x<09
setouttime5
youarrive32
else setouttime10
youarrive34
end
trainarrivesetouttime+traintime
if youarrive
end
end
pronN
概率:
pro 06482
解毕
进行修改:
述解法书写简洁setouttime youarrive写起样会端增加两变量间联系说果面写法setouttime0时候youarrive28者youarrive30样符合题意 Matlab程序修改:
clc
clear
N10000
n0
for i1N
xrand
traintimenormrnd(304)
if x<03
setouttime0
elseif x<07
setouttime0
elseif x<09
setouttime5
else setouttime10
end
xrand
if x<03
youarrive28
elseif x<07
youarrive30
elseif x<09
youarrive32
else
youarrive34
end
trainarrivesetouttime+traintime
if youarrive
end
end
pronN
:pro 06143
解毕
4 蒙特卡罗方法求积分
解:蒙特卡罗方法编写matlab程序:
法:
clear
sum0N10000
for i1N
xunifrnd(0318)
sumsum+15*sin(x)x
end
averagesumN
出:
sum 12098e+004
average 12098
法二:
clear
sum0N10000
asin(03)03 sin(x)x图知03处值18处积区域均0
for i1N
xunifrnd(0318)
yunifrnd(0a)
if y
end
end
square(1803)*a*sumN
:
square 12039
定积分matlab命令int程序算出结果:
syms x
aint(sin(x)x0318)
eval(a)
ans 12073
出蒙特卡罗方法算出结果真实值十分接
文档香网(httpswwwxiangdangnet)户传
《香当网》用户分享的内容,不代表《香当网》观点或立场,请自行判断内容的真实性和可靠性!
该内容是文档的文本内容,更好的格式请下载文档