【数学建模】基于matlab模拟十字路口车辆通行【含Matlab源码 1106期】
作者:互联网
## 一、简介
基于matlab模拟十字路口车辆通行: 用matlab模拟出十字路口的车辆通行情况,车流量可以自己设置,并且绘出了图象能直观地模拟出十字路口的通行状况。
## 二、源代码
```c
clear;clc;
width=30 %道路宽
rl=5*width/8; %左转虚拟车道
rr=1*width/8; %右转虚拟车道
drr=pi/2*rr;
dstr=width-sqrt(rl^2-(width/8)^2); %直行距离
dl=(acos(width/8/rl))*rl; %左拐距离
ck=1.8 ; %车宽
cl=3.8 ; %车长
ddstr=sqrt((rl+ck/2)^2-(width/8+ck/2)^2)-sqrt(rl^2-(width/8)^2);
ddl=(acos(width/8/rl)-acos((width/8+ck/2)/(rl+ck/2)))*rl;
sl=dl;
sstr=dstr;
onetime=160;
dmin=2;
azb=[];
bzb=[];
alcar=[]; %行车矩阵
arcar=[];
astrcar=[];
blcar=[];
brcar=[];
bstrcar=[];
cjjlal=[];
cjjlar=[];
cjjlastr=[];%车间距
cjjlbl=[];
cjjlbr=[];
cjjlbstr=[];%车间距
red=30;
yel=10;
val0=4 ; %a左行车速度(此处设未冲突速度)
var0=5 ; %a右行车速度(此处设未冲突速度)
vastr0=6 ; %a直行车速度(此处设未冲突速度)
vbl0=val0 ; %b左行车速度(此处设未冲突速度)
vbr0=var0 ; %b右行车速度(此处设未冲突速度)
vbstr0= vastr0 ; %b直行车速度(此处设未冲突速度)
val=[];
val(1)=val0 ;
var=[];
var(1)=var0 ;
vastr=[] ;
vastr(1)=vastr0;
vbl=[] ;
vbl(1)=vbl0;
vbr=[];
vbr(1)=vbr0 ;
vbstr=[]
vbstr(1)=vbstr0 ;
dt=0.1 ; %时间步长
alcar(1)=val*dt;
arcar(1)=vbr(1)*dt;
astrcar(1)=vastr(1)*dt;
blcar(1)=vbl(1)*dt;
brcar(1)=vbr(1)*dt;
bstrcar(1)=vbstr(1)*dt;
T=dt;
sumal=1;
sumar=1;
sumastr=1;
sumbl=1;
sumbr=1;
sumbstr=1;
kal=1;
kar=1;
kastr=1;
kbl=1;
kbr=1;
kbstr=1;
dertal=0;
dertas=0;
%外部条件参数===========================================================================================================
yctime=0.5;%加速延迟时间
jsxs=0.7;%减速系数
ajia=8;%最大加速度
ajian=8;%最大减速度
azxgl=1;
ayzxgl=1;
bzxgl=1;
byzxgl=1;
pro=0.02;
sigma=1;
n=20;%画图中的模拟车!!!!!!!!!!!!!!!!!!!!!
ttt=0.000000001;
while T<=onetime
T=T+dt;
lor=mod(floor(T/(red+yel)),2);
goy=mod(T,red+yel);
%虚拟交警================================================================================================================
if kal~=0
cjjlal(1)=0;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%555
end
if kar~=0
cjjlar(1)=0;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%555
end
if kastr~=0
cjjlastr(1)=0;%%%%%%%%%%%%%%%%%%%%%%5
end
if kbl~=0
cjjlbl(1)=0;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%555
end
if kbr~=0
cjjlbr(1)=0;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%555
end
if kbstr~=0
cjjlbstr(1)=0;%%%%%%%%%%%%%%%%%%%%%%5
end
if kbl~=0&&kastr~=0
pbl=dl-blcar(1)-sl;
pastr=dstr-astrcar(1)-sstr;
if pbl<=0&&pastr<=0
ttsl=(dl-blcar(1)-ddl)/vbl(1)+dertal;
ttsstr=(dstr-astrcar(1)-ddstr)/vastr(1)+dertas;
if(ttsstr<=ttsl)
if vastr(1)ttsl)
if vbl(1)ttsl)
if val(1)
标签:ck,1106,width,设未,源码,Matlab,rl,速度,dt 来源: https://blog.51cto.com/u_15287606/2995170