clear all close all clc set(gca,'FontSize',18) linewidth = 2; x = -5:0.01:5; rho = 1/2*(1-tanh(x)); c = 1 - 2*rho; set(gca,'FontSize',18) plot(x,rho,'Linewidth',linewidth) xlabel('x') ylabel('\rho') print -djpeg traffic_example1_rho figure set(gca,'FontSize',18) plot(x,c,'Linewidth',linewidth) xlabel('x') ylabel('c') print -djpeg traffic_example1_c % first draw the characteristics x_0 = [-5:-1,0.75,0.5,0.25,0,-[-5:-1,0.75,0.5,0.25]] rho_0 = 1/2*(1-tanh(x_0)); c_0 = 1 - 2*rho_0; t = 0:0.01:5; figure for j = 1:length(x_0) set(gca,'FontSize',18) plot(x_0(j) + c_0(j)*t,t,'Linewidth',linewidth) axis([-5,5,0,5]) hold on end hold off xlabel('x') ylabel('t') print -djpeg traffic_example1_characteristics figure x = -10:0.01:10; rho = 1/2*(1-tanh(x)); c = 1 - 2*rho; t_range=0:0.2:5; delete traffic_example1.gif %have to delete old one so new one shows up for j=1:length(t_range) set(gca,'FontSize',18) t=t_range(j); plot(x + c*t,rho,'LineWidth',linewidth) grid on axis([-10,10,0,1.1]) title(['t=',num2str(t_range(j) - 0.01,'%1.1f')]) ylabel('\rho(x,t)') xlabel('x') pause(0.1) gif_add_frame(gcf,'traffic_example1.gif',1); end