clear all close all clc set(gca,'FontSize',18) linewidth = 2; x = -5:0.01:5; rho = 1/2*(0.9 -0.3*tanh(100*x)); c = 1 - 2*rho; set(gca,'FontSize',18) plot(x,rho,'Linewidth',linewidth) xlabel('x') ylabel('\rho') axis([-5,5,0,1]) print -djpeg expansion_fan_rho figure set(gca,'FontSize',18) plot(x,c,'Linewidth',linewidth) xlabel('x') ylabel('c') axis([-5,5,-1,1]) print -djpeg expansion_fan_c % first draw the characteristics figure x_0 = [-5:-1,-0.1];x_0 = [x_0,-x_0]; rho_0 = 1/2*(0.9-0.3*tanh(10*x_0)); c_0 = 1 - 2*rho_0; t = 0:0.01:5; for j = 1:length(x_0) set(gca,'FontSize',18) plot(x_0(j) + c_0(j)*t,t,'b','Linewidth',linewidth) axis([-5,5,0,5]) hold on end x_0 = [0.05,0.02,0.01];x_0 = [x_0,-x_0]; rho_0 = 1/2*(0.9-0.3*tanh(10*x_0)); c_0 = 1 - 2*rho_0; t = 0:0.01:5; for j = 1:length(x_0) set(gca,'FontSize',18) plot(x_0(j) + c_0(j)*t,t,'r','Linewidth',linewidth) axis([-5,5,0,5]) hold on end hold off xlabel('x') ylabel('t') print -djpeg expansion_fan_characteristics x = -10:0.01:10; rho = 1/2*(0.9-0.3*tanh(100*x)); c = 1 - 2*rho; t_range=0:0.2:5; delete expansion_fan.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) axis([-10,10,0,1.1]) grid on title(['t=',num2str(t_range(j) - 0.01,'%1.1f')]) ylabel('\rho(x,t)') xlabel('x') pause(0.1) gif_add_frame(gcf,'expansion_fan.gif',1); end