Advertisement
Guest User

AE5139HW5

a guest
Sep 18th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.75 KB | None | 0 0
  1. % AE5139 - Intro to CFD
  2. % Homework 5
  3. % Due: 19 September 2019
  4. % Christopher Bates
  5. % Pastebin Link: https://pastebin.com/Za0ajZKx
  6.  
  7. close all
  8. clear all
  9. clc
  10. trep = [0.05,0.1,0.2,0.5,5];                 % reported time steps
  11.  
  12. t0               = 0;
  13. tf               = max(trep);
  14. numintervals     = 20;                       % number of x intervals
  15. L                = 1;                        % Given length
  16. dx               = L/numintervals;
  17. xloc             = 0:dx:L;                   % Generating mesh
  18. dy               = 0;                        % infinite slab, 1-D HT
  19.  
  20. dt       = tf/10000;     % small number of nodes, so 10000 still runs quickly
  21.  
  22. % Ensuring dt is small enough for stability, in case 10k timesteps is not
  23. if dt > 0.5*(dx^2 + dy^2)
  24.   dt = 0.5*(dx^2 + dy^2);
  25. end
  26.  
  27.  
  28. lambda  = dt/dx^2;
  29. t       = dt:dt:tf;
  30.  
  31. % Initialize mesh
  32. u = zeros(length(t),length(xloc));
  33.  
  34. % Set starting conditions on mesh
  35. u(1,:) = 250*sin(pi.*xloc);                     % K, Given starting temp function
  36. u(1,1)              = 350;                      % K, Boundary condition at x = 0
  37. u(1,numintervals+1) = 420;                      % K, Boundary condition at x = L0 = xmax
  38.  
  39. for i = 2:length(t)
  40.     u(i,1)              = 350;
  41.     u(i,numintervals+1) = 420;
  42.     for j = 2:numintervals
  43.         u(i,j) = lambda*u(i-1,j-1) + (1-2*lambda)*(u(i-1,j))...
  44.             + lambda*u(i-1,j+1);
  45.     end
  46. end
  47.  
  48. figure
  49. hold on
  50. for k = trep
  51.     txt = ['t = ',num2str(k)];
  52.     plot(xloc,u(round(k/dt),:),'DisplayName',txt)
  53. end
  54. grid on
  55. xlabel('Nondimensional Length','Interpreter','latex')
  56. ylabel('Temperature (K)','Interpreter','latex')
  57. title('Temperature Vs. Non-dimensional Length (Explicit Method)','Interpreter','latex')
  58. legend show
  59. legend('Location','best')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement