traffic flow module

142 days ago by swinarsk

2. a

p(x,t) = 1

var('x,t') f(x) = 1 plot(f(x), (x,0,20), axes_labels=['$x$',r'$\rho(x,0)$']) 
       
c=1 
       
characteristics=sum(plot(x/c + E, (x,0,20)) for E in [-5..-1,1..5]) characteristics 
       
characteristics+point([6,2],color='red', pointsize=50) 
       

ρ(6,2) is the same value as ρ(4,0)

f(4).n() 
       
1.00000000000000
 
       
rho(x,t)=f(x-c*t) rho(x,t) 
       
1
plot3d(rho(x,t), (x,0,20), (t,0,12),plot_points=100) 
       
animate([plot(rho(x,t), (x,0,20))+text("time=%d"%t,(10,.5)) for t in [0..5]]).show() 
       

2.b

forget() 
       
var('x,t') f(x) = x+1 plot(f(x), (x,0,20), axes_labels=['$x$',r'$\rho(x,0)$']) 
       
c=1 
       
characteristics=sum(plot(x/c + E, (x,0,20)) for E in [-5..-1,1..5]) characteristics 
       
f(4).n() 
       
5.00000000000000
rho(x,t)=f(x-c*t) rho(x,t) 
       
-t + x + 1
plot3d(rho(x,t), (x,0,20), (t,0,12),plot_points=100) 
       
animate([plot(rho(x,t), (x,0,20))+text("time=%d"%t,(10,.5)) for t in [0..5]]).show() 
       

2.c

forget() var('x,t') f(x) = 1 plot(f(x), (x,0,20), axes_labels=['$x$',r'$\rho(x,0)$']) 
       
c=x+1 
       
characteristics=sum(plot(x/c + E, (x,0,20)) for E in [-5..-1,1..5]) characteristics 
       
f(4).n() 
       
1.00000000000000
rho(x,t)=f(x-c*t) rho(x,t) 
       
1
plot3d(rho(x,t), (x,0,20), (t,0,12),plot_points=100) 
       
animate([plot(rho(x,t), (x,0,20))+text("time=%d"%t,(10,.5)) for t in [0..5]]).show() 
       

prob 3

forget() var('x,t') f(x)=e^(-(x-2)^2) plot(f(x), (x,0,20), axes_labels=['$x$',r'$\rho(x,0)$']) 
       
c=2 
       
characteristics=sum(plot(x/c+E, (x,0,20)) for E in [-5..5]) characteristics 
       
characteristics+point([12,3],color='red', pointsize=50) 
       
f(5).n() 
       
0.000123409804086680
rho(x,t)=f(x-c*t) rho(x,t) 
       
e^(-(2*t - x + 2)^2)
plot3d(rho(x,t), (x,0,20), (t,0,12),plot_points=100) 
       
animate([plot(rho(x,t), (x,0,20))+text("time=%d"%t,(10,.5)) for t in [0..5]]).show() 
       

problem 4

initial condition

ρ(x,t) = 0

forget() var('x,t') f(x)=0 plot(f(x), (x,0,20), axes_labels=['$x$',r'$\rho(x,0)$']) 
       
c=2 
       
characteristics=sum(plot(x/c+E, (x,0,20)) for E in [-5..5]) characteristics 
       
characteristics+point([12,3],color='red', pointsize=50) 
       
f(6).n() 
       
0.000000000000000
rho(x,t)=f(x-c*t) rho(x,t) 
       
0
plot3d(rho(x,t), (x,0,20), (t,0,12),plot_points=100) 
       
animate([plot(rho(x,t), (x,0,20))+text("time=%d"%t,(10,.5)) for t in [0..5]]).show() 
       

ρ(x,t)=x

forget() var('x,t') f(x)=x plot(f(x), (x,0,20), axes_labels=['$x$',r'$\rho(x,0)$']) 
       
c=2 
       
characteristics=sum(plot(x/c+E, (x,0,20)) for E in [-5..5]) characteristics 
       
characteristics+point([12,3],color='red', pointsize=50) 
       
f(6).n() 
       
6.00000000000000
rho(x,t)=f(x-c*t) rho(x,t) 
       
-2*t + x
plot3d(rho(x,t), (x,0,20), (t,0,12),plot_points=100) 
       
animate([plot(rho(x,t), (x,0,20))+text("time=%d"%t,(10,.5)) for t in [0..5]]).show() 
       

ρ(x,t)=x^2

forget() var('x,t') f(x)=x^2 plot(f(x), (x,0,20), axes_labels=['$x$',r'$\rho(x,0)$']) 
       
c=2 
       
characteristics=sum(plot(x/c+E, (x,0,20)) for E in [-5..5]) characteristics 
       
characteristics+point([12,3],color='red', pointsize=50) 
       
f(6).n() 
       
36.0000000000000
rho(x,t)=f(x-c*t) rho(x,t) 
       
(2*t - x)^2
plot3d(rho(x,t), (x,0,20), (t,0,12),plot_points=100) 
       
animate([plot(rho(x,t), (x,0,20))+text("time=%d"%t,(10,.5)) for t in [0..5]]).show() 
       

ρ(x,t)=e^x

forget() var('x,t') f(x)=e^x plot(f(x), (x,0,20), axes_labels=['$x$',r'$\rho(x,0)$']) 
       
c=2 
       
characteristics=sum(plot(x/c+E, (x,0,20)) for E in [-5..5]) characteristics 
       
characteristics+point([12,3],color='red', pointsize=50) 
       
f(6).n() 
       
403.428793492735
rho(x,t)=f(x-c*t) rho(x,t) 
       
e^(-2*t + x)
plot3d(rho(x,t), (x,0,20), (t,0,12),plot_points=100) 
       
animate([plot(rho(x,t), (x,0,20))+text("time=%d"%t,(10,.5)) for t in [0..5]]).show()