Trinh @ Bath

Monotonic shock solutions

This is the caller code. You can call it 'KS_monotonic_caller.m'. Copy the below script and paste the code in and save it in an appropriate directory.

  1. % KS_MONOTONIC_CALLER will solve the K-S equation for the case of the
  2. % monotonic shock conditions
  3. % -------------------------------------------------------------------
  4. %
  5. % Written 19 Mar 2021 for the INI Spring School
  6. % EXPONENTIAL ASYMPTOTICS FOR PHYSICAL APPLICATIONS
  7.  
  8. clear
  9.  
  10. ep = 0.05; % Set epsilon value
  11. zmin = -25; zmax = 12; % Set domain
  12.  
  13. % Define the initial condition at infinity
  14. A = 2;
  15. ubc = @(z) 1 - A*exp(-2*z);
  16. upbc = @(z) -2*(-A)*exp(-2*z);
  17. uppbc = @(z) 4*(-A)*exp(-2*z);
  18. ic = [ubc(zmax); upbc(zmax); uppbc(zmax)];
  19.  
  20. % Define the differential equation
  21. fwd = @(t,Y) KSode(t,Y,ep);
  22.  
  23. % Solve the ODE from z = zmax going backwards to z = zmin
  24. options = odeset('RelTol', 1e-9, 'AbsTol', 1e-9);
  25. [z, Y] = ode45(fwd, [zmax, zmin], ic, options);
  26. u = Y(:,1);
  27.  
  28. figure(1)
  29. hold all
  30. plot(z, u);
  31. plot(z, tanh(z), 'k--');
  32. xlabel('z'); ylabel('u(z)');
  33. ylim([-5,5]);
  34. title('Monotonic shock solution (u0 = tanh(z) shown dashed)');
  35. drawnow

The caller code will require 'KSode.m'. Save it and run it from the same directory. Make sure you name it with the correct upper and lower-case characters.

  1. function Yp = KSode(z, Y, ep)
  2. % KSODE provides the first-order differential equation definition for
  3. % ep^2 u''' + (1 - 4 ep^2) u' = 1 - u^2
  4.  
  5. u = Y(1);
  6. up = Y(2);
  7. upp = Y(3);
  8.  
  9. uppp = (1 - u^2 - (1 - 4*ep^2)*up)/ep^2;
  10.  
  11. Yp = [up; upp; uppp];

Oscillatory shock solutions

Again, you can copy and paste the below script into a Matlab file and call it, e.g. 'KS_osc_caller.m'. It will make use of the 'KSode.m' code above.

  1. % KS_OSC_CALLER will solve the K-S equation for the case of the
  2. % oscillatory shock conditions
  3. % -------------------------------------------------------------------
  4. %
  5. % Written 19 Mar 2021 for the INI Spring School
  6. % EXPONENTIAL ASYMPTOTICS FOR PHYSICAL APPLICATIONS
  7.  
  8. z0 = 1.24;
  9. phi = 2.60586555;
  10. % phi = 2.59;
  11. % phi = 2.5;
  12.  
  13. ep = 0.05;
  14. zmin = -6;
  15. zmax = 12;
  16.  
  17. gam = sqrt(1/ep^2 - 1);
  18. bc = @(z) -1 + exp(-(z-z0))*sin(gam*(z-z0)+phi);
  19.  
  20. bcp = @(z) -exp(-(z-z0))*sin(gam*(z-z0)+phi) + ...
  21. gam*exp(-(z-z0))*cos(gam*(z-z0)+phi);
  22.  
  23. bcpp = @(z) exp(-(z-z0))*sin(gam*(z-z0)+phi) ...
  24. - 2*gam*exp(-(z-z0))*cos(gam*(z-z0)+phi) ...
  25. -gam^2*exp(-(z-z0))*sin(gam*(z-z0)+phi);
  26. ic = [bc(zmax); ...
  27. bcp(zmax); ...
  28. bcpp(zmax)];
  29.  
  30.  
  31. fwd = @(t,Y) KSode(t,Y,ep);
  32.  
  33. mytol = 1e-10;
  34. options = odeset('RelTol', mytol, 'AbsTol', mytol);
  35. sol = ode113(fwd, [zmax, zmin], ic, options);
  36.  
  37. figure(1)
  38. hold all
  39. plot(sol.x, sol.y(1,:));
  40. ylim([-5,5]);
  41. drawnow