• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# AE5139HW5

a guest Sep 18th, 2019 126 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. % AE5139 - Intro to CFD
2. % Homework 5
3. % Due: 19 September 2019
4. % Christopher Bates
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               = 5;
14. numtimesteps     = 20;                       % Short program, so 100 shouldnt take long
15. numintervals     = 20;                       % number of x intervals
16. L                = 1;                        % Given length
17. dx               = L/numintervals;
18. xloc             = 0:dx:L;                   % Generating mesh
19. dy               = 0;                        % infinite slab, 1-D HT
20.
21. dt       = 0.001;
22.
23. % Ensuring dt is small enough for stability
24. if dt > 0.5*(dx^2 + dy^2)
25.   dt = 0.5*(dx^2 + dy^2);
26. end
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(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')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top