a guest Oct 21st, 2019 108 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- function T = myFunction(n,T0,Tend)
- % n is the number of nodes along the rod
- % T0 is the temperature at node zero at x=0
- % Tend is the temperature at the last node at x=L
- % T is a vector of Temperature starting at node zero and going to the last node with Tend.
- % T should have n elements, as the temperature at each node.
- h = 0.01; % [m^-2]
- L = 10; % [m]
- Ta = 20; % C
- % Write your code here:
- onematrix = ones(n-2,1);
- dx = L/(n-1);
- m = h*dx^2;
- A = (2+m)*diag(onematrix)-diag(onematrix(1:end-1),-1)-diag(onematrix(1:end-1),1);
- b = onematrix*m*Ta;
- b(1) = b(1)+T0;
- b(end) = b(end)+Tend;
- T = A\b;
- T = [T0;T;Tend];
- ylabel('Temperature in [C]')
- xlabel('L in [m]')
RAW Paste Data